Loss of messages

Help
2002-10-25
2002-10-30
  • Emmanuel Bourg
    Emmanuel Bourg
    2002-10-25

    Hello, i noticed what seems to be a loss of messages when sending 10000
    messages in burst mode. In a simple subscriber/publisher scenario, the
    subscriber stopped receiving messages shortly after the publisher
    completed his task. I experienced the same issue with a durable
    subscriber and a message listener. Here is the test code i used :

    JMSTestSubscriber.java
    ---------------------------------------------------------
    import javax.jms.*;
    import com.ubermq.jms.client.*;

    public class JMSTestSubscriber
    {
         public static void main(String[] args) throws Exception
         {
             TopicConnectionFactory factory
                 = new UnicastTopicConnectionFactory("127.0.0.1", 3999);
             TopicConnection conn = factory.createTopicConnection();
             conn.start();

             TopicSession session = conn.createTopicSession(false,
    TopicSession.AUTO_ACKNOWLEDGE);
             Topic topic = session.createTopic("test");
             TopicSubscriber subscriber = session.createSubscriber(topic);

             System.out.println("Listening...");

             int n = 0;
             TextMessage message = null;
             while ( (message = (TextMessage)subscriber.receive()) != null)
             {
                 System.out.println("Message " + (n++) + " : "
                                    + message.getText() );
             }
         }
    }

    JMSTestPublisher.java
    ---------------------------------------------------------
    import javax.jms.*;
    import com.ubermq.jms.client.*;

    public class JMSTestPublisher
    {
         public static void main(String[] args) throws Exception
         {
             TopicConnectionFactory factory
                 = new UnicastTopicConnectionFactory("127.0.0.1", 3999);
             TopicConnection conn = factory.createTopicConnection();
             conn.start();

             TopicSession session = conn.createTopicSession(false,
    TopicSession.AUTO_ACKNOWLEDGE);
             Topic topic = session.createTopic("test");
             TopicPublisher publisher = session.createPublisher(topic);

             System.out.println("Publishing...");

             for(int i = 0; i < 10000; i++)
             {
                 Message message = session.createTextMessage("foo " + i);
                 publisher.publish(message);
             }

             System.out.println("done.");
         }
    }

     
    • Jimmy P
      Jimmy P
      2002-10-30

      What's going on here is that you are exiting the application without closing the session and connection. There is a small amount of buffering that can occur on the publish side (both at the network and application level). Closing the session and connection will allow these buffers to be flushed before execution terminates.

      james