如何在jms-spring集成中向消息侦听器bean注入消息选择器? [英] How to inject a message selector to message listener bean in jms-spring integration?

查看:99
本文介绍了如何在jms-spring集成中向消息侦听器bean注入消息选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JMS API(通过HornetQ),并且我正在使用Spring bean作为消息侦听器容器和消息侦听器:

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" />

如果我想要我的消息侦听器,只使用特定的消息(具有相同的StringProperty),该怎么办?我应该在哪里定义选择器?

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

我有以下解决方案,但是我没有MessageConsumer,因此无法向其添加选择器:

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);

推荐答案

您应该可以将其添加到

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

p:messageSelector="color='red'"

这篇关于如何在jms-spring集成中向消息侦听器bean注入消息选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆