简体   繁体   English

Spring JMS在同一应用程序中使用点对点和主题

[英]Spring JMS Use Point-to-point and Topic in the same application

We are currently introducing ActiveMQ into our existing application which was running on a different Queueing system. 当前,我们正在将ActiveMQ引入我们现有的应用程序中,该应用程序运行在不同的队列系统上。 Spring JMS is used to make use of the existing integration within the Spring framework. Spring JMS用于利用Spring框架内的现有集成。

Most of our applications use point-to-point (queue) communication, with the exception of one. 我们的大多数应用程序都使用点对点(队列)通信,只有一个除外。 It needs to be able to listen to the topic created by another producing application while publishing to multiple queues at the same time. 它需要能够在同时发布到多个队列的同时侦听另一个正在生产的应用程序创建的主题。

This means that application needs to support both Topics and Queues. 这意味着应用程序需要同时支持主题和队列。 However, when setting the global property 但是,设置全局属性时

jms:
    pub-sub-domain: true

the setting is global and all queue subscribers are immediately subscribing to topics, which we can see in the ActiveMQ web interface. 该设置是全局设置,所有队列订阅者都立即订阅主题,我们可以在ActiveMQ Web界面中看到这些主题。

Is there a way to configure the application to support both topics and queues at the same time? 有没有一种方法可以配置应用程序以同时支持主题和队列?

The boot property is used to configure the default container factory used by @JmsListener methods, as well as to configure the JmsTemplate . boot属性用于配置@JmsListener方法使用的默认容器工厂,以及配置JmsTemplate

Simply override Boot's default container factory... 只需覆盖Boot的默认容器工厂...

@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
        DefaultJmsListenerContainerFactoryConfigurer configurer,
        ConnectionFactory connectionFactory) {

    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    return factory;
}

and then add a second one 然后添加第二个

@Bean
public DefaultJmsListenerContainerFactory jmsTopicListenerContainerFactory(
        DefaultJmsListenerContainerFactoryConfigurer configurer,
        ConnectionFactory connectionFactory) {

    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    factory.setPubSubDomain(true); << override the boot property
    return factory;
}

Then refer to the alternate factory in the @JmsListener for the topic. 然后,在@JmsListener中参考该主题的替代工厂。

Alternatively, if you don't have listeners for both types, set the property to true , but override Boot's JmsTemplate configuration. 另外,如果您没有两种类型的侦听器,请将属性设置为true ,但覆盖Boot的JmsTemplate配置。

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

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