@JmsListener侦听多个主题仅侦听一个主题

时间:2019-04-26 01:37:57

标签: java spring

我的Spring Boot应用程序的一个类中有两个@jmsListeners,两个都在监听ActiveMQ主题,但是它只监听一个主题,而不能同时监听两个主题。

@JmsListener(destination = "${foo1}", containerFactory = "foo1Factory")
public void onmessage(final Message message) throws JMSException, InvalidProtocolBufferException {
    sysout("Received status message: {}", message);
}

@JmsListener(destination = "${foo2}", containerFactory = "foo2Factory")
public void onmessage(final Message message) throws JMSException, InvalidProtocolBufferException {
    sysout("Received status message: {}", message);
}

// JMS配置:

@Bean
public ConnectionFactory connectionFactory() {

    ActiveMQConnectionFactory connectionFactory = new

    ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL(brokerUrl);
    connectionFactory.setUserName(userName);
    connectionFactory.setPassword(password);
    return connectionFactory;
}
@Bean(name = "foo1Factory")
public DefaultJmsListenerContainerFactory QueueOUTFactory(ConnectionFactory connectionFactory,
        DefaultJmsListenerContainerFactoryConfigurer configurer) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setPubSubDomain(true);
    factory.setConcurrency("1-2");
    configurer.configure(factory, connectionFactory);
    return factory;
}
@Bean(name = "foo2Factory")
    public DefaultJmsListenerContainerFactory QueueOUTFactory1(ConnectionFactory connectionFactory,
            DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setPubSubDomain(true);
        factory.setConcurrency("1-2");
        configurer.configure(factory, connectionFactory);
        return factory;
    }

0 个答案:

没有答案