How to introduce message selector to bean message receiver in jms-spring integration?

I work with the JMS API (with HornetQ) and I use spring beans for the message listener and message listener container:

<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 a message listener, I only consume certain messages (having the same StringProperty), what should I do? Where should I define the selector?

I have a solution below, but I don't have MessageConsumer, so I cannot add a 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); 
+6
source share
1 answer

You can add it to MessageListenerContainer as follows:

p:messageSelector="color='red'"

+7
source

Source: https://habr.com/ru/post/927354/


All Articles