多个目的地和消费者的 Spring 配置 [英] Spring configuration for multiple destinations and consumers

查看:35
本文介绍了多个目的地和消费者的 Spring 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有一个目的地和一个消费者(消息侦听器)的消息侦听器容器:

I'm using a message listener container with one destination and one Consumer (message listener):

<bean id="msgListenerContainer"

  class="org.springframework.jms.listener.DefaultMessageListenerContainer" 

  p:connectionFactory-ref="connectionFactory"

  p:destination-ref="destination"

  p:messageListener-ref="messageHandler"

  p:concurrentConsumers="10"

  p:maxConcurrentConsumers="50"

  p:receiveTimeout="5000"

  p:idleTaskExecutionLimit="10"

  p:idleConsumerLimit="5" />

如果我想要多个目的地,并且每个目的地都有一个消息侦听器,我应该怎么做?如果我想为一个目的地设置多个监听器,我应该怎么做?

If i want multiple destinations and for each destination one message listener, what should i do? And if i want multiple listener for one destination, what should i do?

推荐答案

1) 你需要在你的spring应用上下文中定义每个消息监听器和生产者为bean.像这样的:

1) You need to define each Message Listener and producer in your spring application context as beans. Something like this:

    <!-- MESSAGE LISTENER CONTAINER -->
<bean id="ListListenerContainer"
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="messageListener" ref="messageListener" />
    <property name="connectionFactory" ref="qcf" />
    <property name="destinationResolver" ref="JmsDestinationResolver" />
    <property name="receiveTimeout" value="${jms-timeout}" />
    <property name="destinationName" value="${jms-list-topic}" />
    <property name="concurrency" value="1" />
    <property name="pubSubDomain" value="true" />
    <property name="subscriptionDurable" value="${jms-durable-flag}"/>
    <property name="durableSubscriptionName" value="${jms-list-durable-name}" />
    <property name="clientId" value="${jms-list-client-id}"/>
    <property name="sessionTransacted" value="true"/>
</bean> 


<bean id="publisher-1" class="com.stack.overflow.JmsPublisherImpl">
    <constructor-arg ref="jmsTemplate" />
</bean> 

2) 然后您可以使用自动装配或在应用程序上下文中定义(见下文)在将处理消息的类上设置相关生产者.即上面的 Message Listener bean ref 指向的类:

2) Then you can set the relevant producers using Autowiring or defined in app context(see below) on the class that will handle the message. i.e the class that the Message Listener bean ref above points to:

<bean id="messageListener" class="com.stack.overflow.MessageHandler">
        <property name="publisher" ref="publisher-1" />
</bean>

这只是 1-2-1 映射.对于任何其他路由,您可以添加多个发布者(如上),然后由您决定如何实现所需的路由逻辑来决定哪个主题/队列应该发布从消费者 1 等收到的消息等

This is just 1-2-1 mapping. For any other routing you can add more than one publisher (like above), then it is up to you how you implement the required routing logic to decide which topic/Queues should publish a Message received from Consumer 1 etc etc

这篇关于多个目的地和消费者的 Spring 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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