How to inject a message selector to message listener bean in jms-spring integration?

房东的猫 提交于 2019-12-01 15:57:46

问题


I'm working with JMS API (with HornetQ) and i'm using spring beans for message listener container and message listener:

<bean id="messageListener" class="core.messaging.handler.MessageListener">
    <property name="postCommandService" ref="postCommandService" />
</bean>

<bean id="messageSender"
    class="lsn.messaging.sender.MessageSender">
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="destination" />
</bean>

<bean id="msgListenerContainer"
  class="org.springframework.jms.listener.DefaultMessageListenerContainer" 
  p:connectionFactory-ref="connectionFactory"
  p:destination-ref="destination"
  p:messageListener-ref="messageListener"
  p:concurrentConsumers="10"
  p:maxConcurrentConsumers="50"
  p:receiveTimeout="5000"
  p:idleTaskExecutionLimit="10"
  p:idleConsumerLimit="5" />

If i want my message listener, only consume specific messages (that have same StringProperty) what should i do? Where should i define selector?

I have below solution, but i don't have MessageConsumer and so i can't add selector to it:

     String redSelector = "color='red'";

     MessageConsumer redConsumer = session.createConsumer(queue, redSelector);
     redConsumer.setMessageListener(new SimpleMessageListener("red"));

     TextMessage redMessage = session.createTextMessage("Red");
     redMessage.setStringProperty("color", "red");

     producer.send(redMessage);

回答1:


You should be able to add it to the MessageListenerContainer this way:

p:messageSelector="color='red'"



来源:https://stackoverflow.com/questions/12820306/how-to-inject-a-message-selector-to-message-listener-bean-in-jms-spring-integrat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!