title: Delay while consuming messages from JMS Topic
body: <p>I have a topic with durable subscribers.  I can publish and consume the messages, however I see there is some delay while reading the messages from topic. </p>
  
  <p>I am not able read the messages in a single call. I need to call the method multiple times to read the messages. Am I missing anything?</p>
  
  <pre><code>    private void publishMessage() {
          TopicConnection topicConnection = null;
          TopicSession topicSession = null;
          TopicPublisher topicPublisher = null;
          try {
            topicConnection = connectionFactory.createTopicConnection();
            topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
            Topic topicName= topicSession.createTopic(topicName);
            topicPublisher = topicSession.createPublisher(topicName);
            ObjectMessage message = topicSession.createObjectMessage(customObject)
            message.setStringProperty("user", userProperty);
            topicPublisher.publish(message, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, timeToLive);
          } catch (JMSException e) {
            throw new RuntimeException("Error Sending UMessage", e);
          } finally {
            closeConnections(null, topicPublisher, topicSession, topicConnection);
          }
      }
  
  public void consumeMessages(String userId, int maxResults) {
      TopicConnection topicConnection = null;
      TopicSession topicSession = null;
      TopicSubscriber topicSubscriber = null;
  
      try {
        topicConnection = connectionFactory.createTopicConnection("guest","guest");
        topicConnection.setClientID("topic");
        topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
        Topic topicName= topicSession.createTopic(topicName);
        topicSubscriber = topicSession.createDurableSubscriber(topicName, "subscriptionname", String.format("user = '%s'", userName), false);
        topicConnection.start();
        Message msg = null;
  
        do {
          msg = topicSubscriber.receiveNoWait();
          if (msg instanceof ObjectMessage) {
            ObjectMessage om = (ObjectMessage) msg;
           else {
              log.error(String.format(" %s", om.getObject().getClass().getSimpleName()));
            }
          } else if (msg != null) {
            log.error(String.format("e %s", msg.getClass().getSimpleName()));
          }
        } while (msg != null &amp;&amp; out.size() &lt;= maxResults);
      } catch (JMSException e) {
        throw new RuntimeException("Error retrieving User Messages", e);
      } finally {
        closeConnections(topicSubscriber, null, topicSession, topicConnection);
      }
      return out;
  }
  </code></pre>