2 Replies Latest reply on Jan 13, 2003 9:35 PM by John Tran

    Can not receive published message .....Help

    John Tran Newbie

      Hi, these are the code of a publisher and a subscriber.

      Publisher:

      public class JMSScreenPopPublisher
      {

      public JMSScreenPopPublisher()
      {
      }

      /**
      *
      */
      public static void main(String[] args)
      {
      try
      {
      TopicConnectionFactory topicFactory = (TopicConnectionFactory)EClientCareUtil.getHome("ConnectionFactory");
      Topic topic = (Topic)EClientCareUtil.getHome("topic/testTopic");
      TopicConnection connect = topicFactory.createTopicConnection();
      TopicSession session = connect.createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
      TopicPublisher publisher = session.createPublisher(topic);
      System.out.println(topicFactory);
      TextMessage textMsg = session.createTextMessage();
      textMsg.setText("Blah");
      publisher.setPriority(1);
      for(int i=0; i<10; i++)
      {
      publisher.publish(textMsg);
      }
      publisher.
      publisher.close();
      connect.close();
      }
      catch (Exception ex)
      {
      ex.printStackTrace();
      }

      }
      }


      --------------------------------------------

      Subscriber:

      public class JMSScreenPopSubscriber implements javax.jms.MessageListener
      {

      public JMSScreenPopSubscriber()
      {
      try
      {
      System.out.println("Subscriber");
      TopicConnectionFactory topicFactory = (TopicConnectionFactory)EClientCareUtil.getHome("ConnectionFactory");
      Topic topic = (Topic)EClientCareUtil.getHome("topic/testTopic");
      TopicConnection connect = topicFactory.createTopicConnection();
      TopicSession session = connect.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
      TopicSubscriber subscriber = session.createSubscriber(topic);
      subscriber.setMessageListener(this);
      connect.start();
      }
      catch (Exception ex)
      {
      ex.printStackTrace();
      }
      }

      /**
      *
      */
      public static void main(String[] args)
      {
      try
      {
      JMSScreenPopSubscriber subscriber = new JMSScreenPopSubscriber();
      while(true)
      {
      Thread.sleep(1000);
      }
      }
      catch (Exception ex)
      {
      ex.printStackTrace();
      }


      }

      public void onMessage(Message msg)
      {
      try
      {
      TextMessage textMsg = (TextMessage)msg;
      String text = textMsg.getText();
      System.out.println("\n Received Message: "+text);
      }
      catch (Exception ex)
      {
      ex.printStackTrace();
      }
      }
      }


      I ran the publisher first and then the subscriber, both ran without any error. But the receiver does not receive the message "Blah" from the publisher. Please tell me what I did wrong. Thanks.