title: Exception while trying to consume a JMS Topic message using Spring Boot
body: <p>I am trying to consume message from ActiveMQ Topic. Below is the Code: </p>
  
  <pre><code>@Configuration
  @EnableJms
  public class Config {
  
  @Value("${activemq.broker-url}")
  private String brokerURL;
  
  @Bean
  public ActiveMQConnectionFactory activeMQConnectionFactory() {
      ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
      activeMQConnectionFactory.setBrokerURL(brokerURL);
      activeMQConnectionFactory.setTrustAllPackages(true);
      return activeMQConnectionFactory;
  }
  
  public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(){
      DefaultJmsListenerContainerFactory defaultJmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
      defaultJmsListenerContainerFactory.setConnectionFactory(activeMQConnectionFactory());
      defaultJmsListenerContainerFactory.setPubSubDomain(true);
      return defaultJmsListenerContainerFactory;
  }
  </code></pre>
  
  <p>My Consumer Code: </p>
  
  <pre><code>@Component
  @EnableJms
  public class Consumer {
  
     @JmsListener(destination = "xml.inbound.topic", containerFactory = "jmsListenerContainerFactory")
     public void Processor(final Message xmlMessage) {
  
     }
  }
  </code></pre>
  
  <p>The Exception which I am getting is: </p>
  
  <p><em>Unsatisfied dependency expressed through field 'jmsTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource [com/investmentbank/equityfeedsprocessingrevised/config/Config.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jms.core.JmsTemplate]: Factory method 'jmsTemplate' threw exception; nested exception is java.lang.ClassCastException: class org.springframework.jms.config.DefaultJmsListenerContainerFactory cannot be cast to class javax.jms.ConnectionFactory (org.springframework.jms.config.DefaultJmsListenerContainerFactory and javax.jms.ConnectionFactory are in unnamed module of loader 'app')</em></p>
  
  <p>What am I doing wrong here ? Why the exception?</p>
  
  <p>I have also tried : </p>
  
  <pre><code>@Bean
  public DefaultMessageListenerContainer jmsListenerContainerFactory() {
          DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
          dmlc.setConnectionFactory(activeMQConnectionFactory());
          dmlc.setPubSubDomain(true);
          return dmlc;
  }
  </code></pre>
  
  <p>The Exception which I get here is: </p>
  
  <p><em>Unsatisfied dependency expressed through field 'jmsTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource [com/investmentbank/equityfeedsprocessingrevised/config/Config.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jms.core.JmsTemplate]: Factory method 'jmsTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsListenerContainerFactory' defined in class path resource [com/investmentbank/equityfeedsprocessingrevised/config/Config.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'destination' or 'destinationName' is required</em></p>
  
  <p>Just to add my JmsTemplate code looks like this: </p>
  
  <pre><code>@Bean
  public JmsTemplate jmsTemplate() {
  JmsTemplate jmsTemplate = new JmsTemplate();
           jmsTemplate.setConnectionFactory(activeMQConnectionFactory());
           jmsTemplate.setPubSubDomain(true);
           return jmsTemplate;
  }
  </code></pre>
  
  <p>I have implemented the JMS Topic Publisher using Apache Camel (Code):</p>
  
  <pre><code>ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
          CamelContext _ctx = new DefaultCamelContext(); 
          _ctx.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
          _ctx.addRoutes(new RouteBuilder() {
  
              public void configure() throws Exception {
                  from("file:src/main/resources?fileName=data-sample_2.csv")
                  .process(new MyTransformRevised1())
                  .to("file:src/main/resources/?fileName=emp.xml")                
                  .split(body().tokenizeXML("equityFeeds", null)).streaming().to("jms:topic:xml.inbound.topic");
              }
  
          });
  </code></pre>
  
  <p>I am able to see the number of messages in "Message Enqueued" column of my Topic name.</p>
  
  <p>What is going wrong ? I have read various posts on net but not able to solve the issue. Kindly help in resolving the issue. I am not able to read the message on ActiveMQ Topic. Let me know if some information is missing from my end. </p>