繁体   English   中英

在ActiveMQ中使用Spring Integration JMS实现发布订阅

[英]Implementing Publish Subscribe using Spring Integration JMS in ActiveMQ

我已经使用ActiveMQ中的Spring Integration API的PublishSubscribe Channel开发了生产者和消费者。 我可以使用实现发布和接收消息,但是只有一个服务激活器以循环方式使用消息。 我需要确定是否正确。 以下是我的配置:

生产方:

<int:publish-subscribe-channel id="jmsPubSubChannel" />

<int-jms:outbound-channel-adapter channel="jmsPubSubChannel"
                                      destination-name="${jms.topic.name}"
                                      pub-sub-domain="true" 
                                      connection-factory="connectionFactory" />

<!-- Define the ActiveMQ connection factory -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
        <property name="brokerURL" value="${jms.broker.url}"/>
        <property name="userName" value="${jms.username}" />
        <property name="password" value="${jms.password}" />
</bean>

消费者方:

<jms:message-driven-channel-adapter id="messageDrivenAdapter"
                                            channel="jmsPubSubChannel"
                                            destination-name="${jms.topic.name}"
                                            pub-sub-domain="true" />

<!-- Subscriber - offeringmsg -->
<int:service-activator id="offeringmsg1" input-channel="jmsPubSubChannel" ref="impl1" />

<int:service-activator id="offeringmsg2" input-channel="jmsPubSubChannel" ref="impl2" />

<bean id="impl1" class="com.intuit.imp.mql.MessageListenerImpl" />

<bean id="impl2" class="com.intuit.imp.mql.MessageListenerImpl2" />

<!-- Define the ActiveMQ connection factory -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
            <property name="brokerURL" value="${jms.broker.url}"/>
            <property name="userName" value="${jms.username}" />
            <property name="password" value="${jms.password}" />
</bean>

您需要添加

<int:publish-subscribe-channel id="jmsPubSubChannel" />

在消费者方面。

如果未显式声明通道,则默认为具有循环语义的直接通道。

在生产者方面,由于只有一个使用者(出站通道适配器),因此那里不需要是发布/订阅通道。

暂无
暂无

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

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