a problem Pub/Sub message

Help
2002-12-13
2002-12-13
  • Sin Le Roop

    Sin Le Roop - 2002-12-13

    I have try to write simple example:

    JmsPubTest.java

    package forum;

    import javax.jms.*;
    import com.ubermq.jms.client.UnicastTopicConnectionFactory;

    public class JMSPubTest {
        private static TopicConnectionFactory topicConnectionFactory = null;
        private static Topic myTopic = null;
        protected static TopicConnection topicConnection = null;
        protected static TopicSession topicSession = null;
        protected static TopicPublisher quotePublisher;

        public static void main(String[] args) throws Exception {
            try {
                topicConnectionFactory = new UnicastTopicConnectionFactory("localhost", 3999);
                topicConnection = topicConnectionFactory.createTopicConnection();
                topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);

                myTopic = topicSession.createTopic("test");
                quotePublisher = topicSession.createPublisher(myTopic);
                int i;
                for (i=0; i<1000; i++)
                {
                    TextMessage m = topicSession.createTextMessage("Hello World " +i);
                    m.setStringProperty("subject", "testsubject " + i);
                    quotePublisher.publish(m);
                }
                System.out.println("Successful "+i);

            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }

    JMSSubTest.java
    package forum;

    import javax.jms.*;
    import com.ubermq.jms.client.UnicastTopicConnectionFactory;

    public class JMSSubTest {
        private static TopicConnectionFactory topicConnectionFactory = null;
        private static Topic myTopic = null;
        protected static TopicConnection topicConnection = null;
        protected static TopicSession topicSession = null;
        protected static TopicSubscriber quoteSubscriber;

        public static void main(String[] args) throws Exception{
            try {
                topicConnectionFactory = new UnicastTopicConnectionFactory("localhost", 3999);
                topicConnection = topicConnectionFactory.createTopicConnection();
                topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                myTopic = topicSession.createTopic("test");

                String selector = "Where subject = 'testsubject'";
                quoteSubscriber = topicSession.createDurableSubscriber(myTopic, "sub1", null, false);
                quoteSubscriber.setMessageListener(new TestListener());

                topicConnection.start();
                System.out.println("Waiting...");
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }

    TestListener.java

    package forum;

    import javax.jms.Message;
    import javax.jms.TextMessage;
    import javax.jms.MessageListener;
    import javax.jms.JMSException;

    public class TestListener implements MessageListener {
        public void onMessage(Message message) {
            System.out.println("Received Message");
            try {
                if (message instanceof TextMessage) {
                    TextMessage m = (TextMessage) message;
                    System.out.println(m.getText());
                }
            } catch (JMSException e) {
                System.out.println("JMSException: " + e);
            }
        }
    }

    Result:
    Publishes all message: "Successful 1000", but Subscriber doesn't receive all messages, it only receivers 54 messages

    Everyone think ......??????

    Roop Sin

     
    • Sin Le Roop

      Sin Le Roop - 2002-12-13

      I have just try to test with "quoteSubscriber = topicSession.createSubscriber(myTopic, null, false);", then it only receives 76 message.

      ???????

      Roop Sin

       

Log in to post a comment.