How to configure multiple JmsListenerContainerFactories from multiple JNDI names of JMS in Springboot application?

Viewed 104

I should be able to configure multiple JmsListenerContainerFactory beans from multiple JMS JNDI names configured in the server and I should be able to do the following.

@EnableJms
@Configuration
public class JmsConfig
{
    @Bean
    public JmsListenerContainerFactory<?> containerFactoryONE(@Qualifier("from-JNDI-ONE") ConnectionFactory connectionFactory,
    DefaultJmsListenerContainerFactoryConfigurer configurer)
    {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

        configurer.configure(factory, connectionFactory);

        return factory;
    }
    
    @Bean
    public JmsListenerContainerFactory<?> containerFactoryTWO(@Qualifier("from-JNDI-TWO") ConnectionFactory connectionFactory,
    DefaultJmsListenerContainerFactoryConfigurer configurer)
    {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

        configurer.configure(factory, connectionFactory);

        return factory;
    }
}

and should be able to listen to the message from two different servers as below

@Component
public class JMSListener
{

    @JmsListener(destination = "jms/ActiveMQ-Server-ONE", containerFactory="containerFactoryONE")
    public void receiveMessageFromJMSServerONE(String message)
    {
        System.out.println(message);
    }
    
    @JmsListener(destination = "jms/ActiveMQ-Server-TWO", containerFactory="containerFactoryTWO")
    public void receiveMessageFromJMSServerTWO(String message)
    {
        System.out.println(message);
    }
}
0 Answers
Related