title: Consumer not consuming messages when created dynamically
body: <p>I am learning to implement active mq interface in my project. This is how I am creating producers and consumers. </p>
  
  <pre><code>public void connectionSetup(String portName) { // portname is object of PortTO class.   We are creating producer and consumer pair for every existing PortTO object.
              Connection connection = null; 
              try { 
  
                      if (timeToLive != 0) { 
  
                      } 
  
                      // Create the connection. 
                      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); 
                      connection = connectionFactory.createConnection(); 
  
                      connection.start(); 
                      connection.setExceptionListener(this); 
  
                      // Create the session 
                      Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); 
                      if (topic) { 
                              destination = session.createTopic(subject); 
                      } else { 
                              destination = session.createQueue(portName); 
                      } 
  
                      // Create the producer. 
                      MessageProducer producer = session.createProducer(destination);                        if (persistent) { 
                              producer.setDeliveryMode(DeliveryMode.PERSISTENT); 
                      } else { 
                              producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 
                      } 
  
  
                      MessageConsumer consumer = session.createConsumer(destination);                        if (timeToLive != 0) 
                              producer.setTimeToLive(timeToLive); 
  
                      mapOfSession.put(portName, session); 
                      mapOfMessageProducer.put(portName, producer); 
                      mapOfMessageConsumer.put(portName, consumer);                        log.info("Producer is " + producer); 
                      log.info("Consumer is " + consumer); 
  
              } catch (Exception e) { 
  
                      log.error(e.getMessage()); 
              } 
      } 
  </code></pre>
  
  <p>So, we are creating producer and consumer and storing them in a map for every PortTO object. Now, producer is sending messages:</p>
  
  <pre><code>TextMessage message = session.createTextMessage(); 
   message.setIntProperty(key, 2); 
    producer.send(message);        
  </code></pre>
  
  <p>But consumer is not consuming it... </p>
  
  <pre><code>        public void onMessage(Message message) { 
              PortService portService = new PortService();      
             List&lt;PortTO&gt; portTOList = portService.getMoxaPorts(); 
                      for(PortTO portTO : portTOList) {  // catching messages from producers of every PortTO object                                
                MessageConsumer consumer = DataCollectionMessageProducer.getMapOfMessageConsumer().get(portTO.getPort());  // getting consumer from map of PortTO
                              consumer.setMessageListener(this); 
                              message = consumer.receive(1000);                                if (message instanceof TextMessage) { 
              / / some processing 
                           } 
                              } else { 
                                      if (verbose) { 
  
                                      } 
                              } 
  
                      } 
                      } 
  </code></pre>
  
  <p>What can be the reason? Is my approach wrong ?? </p>