title: Why does my JMS client not consume messages from the Topic?
body: <p>I have ActiveMQ running on the localhost using the default port, 61616. I put some messages in a Topic called <code>topic.STUDENTS</code>. I have a client program that I am trying to use to read the messages in the Topic. Here is the main part of the program that does not work as expected. I was expecting to get some of the message back but instead I just receive <code>null</code>. </p>
  
  <pre><code> public void receiveMessages() throws URISyntaxException, JMSException, Exception {
  
      try { 
      //Create a ConnectionFactory 
      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
  
      //Create a Connection
      Connection connection = connectionFactory.createConnection();
      connection.start();
  
      //Create a session
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  
      //Create the destination (Topic or Queue)
      Destination destination = session.createTopic("topic.STUDENTS");
  
      //Create a MessageConsumer from the Session to the Topic or Queue
      MessageConsumer consumer = session.createConsumer(destination);
  
      //Wait for a message
      Message message = consumer.receive(1000);
  
      if (message instanceof TextMessage) { 
          TextMessage textMessage = (TextMessage) message;
          String text = textMessage.getText();
          System.out.println("Received: " + text);
  
      } else { 
          System.out.println("Received: " + message);
      }
  
      consumer.close();
      session.close();
      connection.close();
  
         } catch(Exception e) { 
          System.out.println("Caught: " + e);
          e.printStackTrace();
      }
      }
  </code></pre>
  
  <p>This code basically apes the code from ActiveMQ 'Hello World' example: <a href="http://activemq.apache.org/hello-world.html" rel="nofollow">http://activemq.apache.org/hello-world.html</a> </p>
  
  <p>Does anyone know why I do not receive any messages from the Topic? Here is one message that is in the Topic that I can see through the <code>./activemq browse topic.STUDENTS</code> command: </p>
  
  <pre><code>JMS_BODY_FIELD:JMSText = Invention-my-dear-friends-is-93%-perspiration-6%-electricity
  JMS_HEADER_FIELD:JMSExpiration = 0
  JMS_HEADER_FIELD:JMSMessageID = ID:user-thinkpad-335i-59919-1457977678059-1:1:1:1:3
  JMS_HEADER_FIELD:JMSPriority = 4
  JMS_HEADER_FIELD:JMSDestination = topic.STUDENTS
  JMS_HEADER_FIELD:JMSTimestamp = 1457977678409
  JMS_HEADER_FIELD:JMSRedelivered = false
  JMS_HEADER_FIELD:JMSDeliveryMode = persistent
  </code></pre>