8

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);
Arya
  • 2,809
  • 5
  • 34
  • 56

1 Answers1

8

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

p:messageSelector="color='red'"

Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125
  • 1
    Thanks! Can MessageListenerContainer have more than one destination? or more than one messageListener? – Arya Oct 10 '12 at 14:22
  • 3
    For more than 1 destination you can probably just register more messagelistenercontainers - regarding more than 1 messagelistener per container - you can essentially dispatch it internally within the messagelistener - get the message inside the messagelistener and delegate the message to more beans inside the messagelistener. – Biju Kunjummen Oct 10 '12 at 14:36