简体   繁体   English

使用Spring JMS发布订阅实现

[英]Publish subscribe implementation with Spring JMS

I have a JMS queue implementation with JmsTemplate . 我有一个JmsTemplate的JMS队列实现。 I want to have more than one listener when a message is put in the queue, ie I want to use topic instead of queue. 将消息放入队列时,我希望有多个侦听器,即,我想使用主题而不是队列。

I have configuration without JMS namespacing. 我没有JMS名称空间配置。 What are the changes that need to be made to have multiple listeners listen on a topic when someone sends a message in a topic. 当某人在某个主题中发送消息时,要使多个侦听器侦听该主题,需要进行哪些更改。

I guess you are probably using DefaultMessageListenerContainer . 我猜您可能正在使用DefaultMessageListenerContainer Just to be sure, you want that several individual components receive the same message (ie you don't want to process messages in parallel). 可以肯定的是,您希望多个组件收到相同的消息(即,您不想并行处理消息)。

Assuming I got this right and component A and compoent B should receive the same message, you simply create two DefaultMessageListenerContainer instance on the same topic and you set the pubSubDomain property to true . 假设我没错,并且组件A和组件B应该收到相同的消息,则只需在同一主题上创建两个DefaultMessageListenerContainer实例,然后将pubSubDomain属性设置为true Make sure you haven't set any concurrency on the listener container, or better yet, set the concurrency to 1 to make that explicit. 确保尚未在侦听器容器上设置任何并发,或者更好的做法是,将并发设置为1以使其明确。

This would give something like 这会给像

<bean id="listener1"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="pubSubDomain" value="true"/>
    <property name="concurrency" value="1"/>
    <property name="destinationName=" value="...."/> <!-- topic name -->
    <property name="messageListener" ref="...."/> 
</bean>

Then you should create a similar bean for the second component. 然后,您应该为第二个组件创建一个类似的bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM