【问题标题】:Simple publish/subscribe with spring-integration使用弹簧集成进行简单的发布/订阅
【发布时间】:2015-07-29 07:02:26
【问题描述】:

我在 spring-boot application.properties 中有一个队列和主题设置,如下所示:

spring.hornetq.embedded.queues=parts.queue
spring.hornetq.embedded.topics=parts.topic

我需要从一个应用程序向另一个应用程序发送消息。

app1 (publisher)
app2 (subscriber)
bridge (contains the integration code)

我从 app1 发布的部分如下:

this.jmsTemplate.convertAndSend("parts.queue", message);

在桥接项目中,我在queue 上获取它,然后将其路由到topic

<int:channel id="partsChannel" />

<int-jms:message-driven-channel-adapter
    id="jmsPartsInbound"
    acknowledge="transacted"
    destination-name="parts.queue"
    channel="partsChannel"
    connection-factory="jmsConnectionFactory"
    />

<int-jms:outbound-channel-adapter
    id="jmsPartsOutbound"
    destination-name="parts.topic"
    channel="partsChannel"
    connection-factory="jmsConnectionFactory"
    pub-sub-domain="true"
    >
    <int-jms:request-handler-advice-chain>
        <int:retry-advice max-attempts="3">
            <int:exponential-back-off initial="2000" multiplier="2" />
        </int:retry-advice>
    </int-jms:request-handler-advice-chain>
</int-jms:outbound-channel-adapter>

app2 然后订阅parts.topic 并处理消息。

这是可行的,但是,上面的桥接代码似乎对于我正在尝试做的事情来说可能是一种矫枉过正。我猜我只需要一个parts.topic 而根本不需要parts.queue。

上面的spring-integration XML可以用某种方式简化吗?

【问题讨论】:

    标签: spring-integration hornetq


    【解决方案1】:

    不完全清楚为什么你不能只使用...

    this.jmsTemplate.convertAndSend("parts.topic", message);
    

    【讨论】:

    • 是的,这就是我现在对答案中的配置所做的事情。根本不需要排队。
    【解决方案2】:

    好吧,我找到了一个更简单的解决方案:

    <int-jms:publish-subscribe-channel id="partsPubSubChannel" topic-name="parts.topic" connection-factory="jmsConnectionFactory"/>
    

    不需要队列,也不需要设置 jmsTemplate 以在 application.properties 中使用 spring.jms.pub-sub-domain=true

    this.jmsTemplate.convertAndSend("parts.topic", message);

    就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-23
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-07
      • 2018-04-08
      • 1970-01-01
      相关资源
      最近更新 更多