【问题标题】:Implementing Publish Subscribe using Spring Integration JMS in ActiveMQ在 ActiveMQ 中使用 Spring Integration JMS 实现发布订阅
【发布时间】:2016-12-03 06:44:42
【问题描述】:

我在 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>

【问题讨论】:

    标签: java activemq spring-integration spring-jms


    【解决方案1】:

    你需要添加

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

    在消费者方面。

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

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

    【讨论】:

    • 谢谢。如果在生产者方面我需要添加更多消费者,那么需要添加什么。
    • 我不明白这个问题;从 Spring Integration 的角度来看,该通道上唯一的消费者是出站通道适配器。如果您需要将其发送到多个主题,请将其保留为 pub 子频道并为每个主题添加一个适配器。
    • 对不起,我错了。测试了我在 Producer 端添加了一个适配器以发送到另一个主题。在消费者端更改为发布订阅通道使服务激活器都可以使用消息。工作完美。伟大的。再次感谢。
    • 太好了——如果它回答了你的问题,这里习惯于“接受”答案(点击投票按钮下方的勾号/复选标记)——这将有助于其他人寻找答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 2021-06-09
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    相关资源
    最近更新 更多