用于多个目标和使用者的Spring配置

用于多个目标和使用者的Spring配置,第1张

概述我正在使用一个消息侦听器容器,其中有一个目的地和一个消费者(消息侦听器):<bean id='msgListenerContainer' class='org.springframework.jms.listener.DefaultMessageListenerContainer' p:connectionFactory-ref='con

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

<bean ID="msgListenerContainer"     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" />

如果我想要多个目的地,并且对于每个目的地一个消息侦听器,我该怎么办?
如果我要在一个目的地使用多个侦听器,该怎么办?最佳答案1)您需要在Spring应用程序上下文中将每个消息侦听器和生产者定义为bean.像这样:

    <!-- MESSAGE ListENER CONTAINER --><bean ID="ListListenerContainer"    >    <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" >    <constructor-arg ref="jmstemplate" /></bean> 

2)然后,您可以使用自动装配或在应用上下文中定义的相关生产者(请参见下文)在将处理消息的类上进行设置.即上面的消息侦听器bean引用指向的类:

<bean ID="messageListener" >        <property name="publisher" ref="publisher-1" /></bean>

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

以上是内存溢出为你收集整理的用于多个目标和使用者的Spring配置 全部内容,希望文章能够帮你解决用于多个目标和使用者的Spring配置 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1239825.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存