Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 911
Arya Avatar asked Oct 10 '12 13:10

Arya


1 Answers

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

p:messageSelector="color='red'"

like image 135
Biju Kunjummen Avatar answered Oct 17 '22 22:10

Biju Kunjummen