title: Spring Boot JMS Topic not working
body: <p>Spring Boot JMS Topic not working properly it behave like queue.</p>
  
  <p>Sample code</p>
  
  <p>Application</p>
  
  <pre><code>@SpringBootApplication
  public class Application extends SpringBootServletInitializer {
  
    public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
    }
  }
  </code></pre>
  
  <p>JMSConfig</p>
  
  <pre><code>@Configuration
  @EnableJms
  public class JMSConfig {
  
  private static final String JMS_BROKER_URL = "vm://embedded?broker.persistent=false,useShutdownHook=false";
  public static final String JMS_TOPIC_MAIL = "mailbox.topic";
  
  @Bean
  // Serialize message content to json using TextMessage
  public MessageConverter jacksonJmsMessageConverter() {
      MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
      converter.setTargetType(MessageType.TEXT);
      converter.setTypeIdPropertyName("_type");
      return converter;
  }
  
  @Bean
  public ActiveMQConnectionFactory amqConnectionFactory() {
  
      return new ActiveMQConnectionFactory(JMS_BROKER_URL);
  
  }
  
  @Bean
  public CachingConnectionFactory connectionFactory() {
  
      return new CachingConnectionFactory(amqConnectionFactory());
  
  }
  
  @Bean
  public ActiveMQTopic destinationTopic() {
  
      return new ActiveMQTopic(JMS_TOPIC_MAIL);
  }
  
  @Bean
  public JmsTemplate jmsTemplate() {
  
      JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
      // jmsTemplate.setDefaultDestination(destinationTopic());;
      jmsTemplate.setDefaultDestinationName(JMS_TOPIC_MAIL);
      jmsTemplate.setConnectionFactory(connectionFactory());
      jmsTemplate.setMessageConverter(jacksonJmsMessageConverter());
      return jmsTemplate;
  }
  
  @Bean
  public JmsListenerContainerFactory&lt;?&gt; jmsListenerContainerFactory(
          ConnectionFactory connectionFactory,
          DefaultJmsListenerContainerFactoryConfigurer configurer) {
      DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
      factory.setPubSubDomain(true);
      factory.setConnectionFactory(connectionFactory());
      // This provides all boot's default to this factory, including the
      // message converter
      configurer.configure(factory, connectionFactory());
      // You could still override some of Boot's default if necessary.
      return factory;
  }
  }
  </code></pre>
  
  <p>Here listeners are </p>
  
  <p>First listener</p>
  
  <pre><code>@Component
  public class JMSTopicListener1 {
  
  @JmsListener(destination = JMSConfig.JMS_TOPIC_MAIL, containerFactory = "jmsListenerContainerFactory")
  public void receiveTopicMessage(Email email) {
      System.out.println("JMSTopicListener#1 Received &lt;" + email + "&gt;");
  }
  }
  </code></pre>
  
  <p>Second listener </p>
  
  <pre><code>@Component
  public class JMSTopicListener2 {
  
  @JmsListener(destination = JMSConfig.JMS_TOPIC_MAIL, containerFactory = "jmsListenerContainerFactory")
  public void receiveTopicMessage(Email email) {
      System.out.println("JMSTopicListener#2 Received &lt;" + email + "&gt;");
  }
  }
  </code></pre>
  
  <p>Access through web</p>
  
  <pre><code>@RestController
  public class WebController {
  
  @Autowired
  JmsTemplate jmsTemplate;
  
  
  @RequestMapping("/sendEmail")
  public String sendEmail() {
  
      System.out.println("Sending ************************ .");
  
      jmsTemplate.convertAndSend(JMSConfig.JMS_TOPIC_MAIL, new Email(
              "info@example.com", "Hello"));
  
  
      return "Email send success!!!";
  }
  }
  </code></pre>
  
  <p>Ouput is </p>
  
  <p>Sending ************************ .
  JMSTopicListener#2 Received </p>
  
  <p>But message should be subscribed by both listener because it attached with Topic</p>