spring-bootspring-jmsjms-topicjmstemplatejms-queue

Is it possible to configure a jmsTemplate Topic publisher and also a Queue message producer in the same springboot application


My application is using a Queue Originally, So I need to also Implement a Topic for the same application. I'm having difficulties setting up the configurations. please help guys


Solution

  • Just define two JmsTemplate beans

        @Bean
        public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
            JmsTemplate template = new JmsTemplate(connectionFactory);
            template.setPubSubDomain(false);
            return template;
        }
    
        @Bean
        public JmsTemplate jmsTemplatePubSub(ConnectionFactory connectionFactory) {
            JmsTemplate template = new JmsTemplate(connectionFactory);
            template.setPubSubDomain(true);
            return template;
        }
    

    This will prevent Boot from declaring its own template