1 Reply Latest reply on Apr 5, 2002 6:53 PM by David Martinez

    JBoss 2.4.1 getJMSReplyTo() broken for request/reply

    llmercy Newbie

      I'm using the TopicRequestor and temporary topics to implement a
      request/reply system as shown in the O'Reilly JMS book. It works
      under JBoss 2.2.2, but breaks under JBoss 2.4.1. Instead of giving
      a long winded explanation, I'm attaching two test programs. The
      ReplySubscriber creates a subscription, waits for a message and
      replies back using the topic in the message. The ReplyPublisher
      sends the message using the TopicRequestor and request() method.
      Both JBoss installations are from the binaries and run without
      modification under Sun's JDK 1.3.1 on Solaris 8. When run under
      JBoss 2.4.1, the ReplySubscriber hangs when it tries to get the
      message's topic with the method getJMSReplyTo().

      Is there some configuration difference I'm missing. Any help would
      be greatly appreciated since we cannot upgrade until this is fixed.
      Thank you in advance for your help.

      llmercy

      ------------------------------ ReplySubscriber ------------------------------

      import java.io.*;
      import java.util.*;
      import javax.jms.*;
      import javax.naming.*;

      /**
      * Subscribe to a message and reply using the temporary topic.
      */
      public class ReplySubscriber implements MessageListener {
      private TopicConnectionFactory connectionFactory = null;
      private TopicConnection connection = null;
      private Topic topic = null;
      private TopicSession pubSession = null;
      private TopicSession subSession = null;
      private TopicSubscriber subscriber = null;

      /**
      * Main to run the test as an application.
      *
      * @param arg the command line arguments
      */
      public static void main(String [] args) {
      System.setProperty("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.provider.url", "localhost:1099");
      ReplySubscriber test = new ReplySubscriber();

      // Wait for key input.
      System.out.println(" Waiting for messages (press any key to exit)...");
      InputStreamReader in = new InputStreamReader(System.in);
      try {
      while (true) {
      if (in.ready()) {
      in.close();
      System.exit(0);
      } else {
      try {
      Thread.sleep(200);
      } catch (InterruptedException e) { }
      }
      }
      } catch (IOException e) { }
      }

      /**
      * Creates the subscriber.
      */
      public ReplySubscriber() {
      try {
      InitialContext jndi = new InitialContext();
      topic = (Topic)jndi.lookup("topic/testTopic");
      connectionFactory = (TopicConnectionFactory)jndi.lookup(
      "TopicConnectionFactory");
      connection = connectionFactory.createTopicConnection();
      pubSession = connection.createTopicSession(false,
      Session.AUTO_ACKNOWLEDGE);
      subSession = connection.createTopicSession(false,
      Session.AUTO_ACKNOWLEDGE);
      topic = (Topic)jndi.lookup("topic/testTopic");
      subscriber = subSession.createSubscriber(topic);
      subscriber.setMessageListener(this);
      connection.start();
      } catch (Exception e) {
      System.err.println("ERROR: " + e.toString());
      }
      }

      /**
      * Subscriber message event method.
      *
      * @param message the received message
      */
      public void onMessage(Message message) {
      publish((TextMessage)message);
      }

      /**
      * Send a message using the topic in the message.
      *
      * @param message the received message
      */
      private void publish(TextMessage message) {
      try {
      System.out.println("received: \"" + message.getText() + '\"');
      System.out.println("getting topic from message...");
      TemporaryTopic tempTopic = (TemporaryTopic)message.getJMSReplyTo();
      System.out.println("creating publisher from topic...");
      TopicPublisher publisher = pubSession.createPublisher(tempTopic);
      TextMessage newMessage = pubSession.createTextMessage();
      newMessage.setText("Received: " + message.getText());
      System.out.println("publishing to topic: " +
      tempTopic.getTopicName());
      publisher.publish(newMessage, DeliveryMode.NON_PERSISTENT,
      Message.DEFAULT_PRIORITY, 1800000);
      System.out.println("message published");
      } catch (JMSException e) {
      System.err.println("ERROR: " + e.toString());
      }
      }
      }

      ------------------------------ ReplyPublisher ------------------------------

      import java.io.*;
      import java.util.*;
      import javax.jms.*;
      import javax.naming.*;

      /**
      * Sends a request and waits for a reply using a temporary topic.
      */
      public class ReplyPublisher {
      private TopicConnectionFactory connectionFactory = null;
      private TopicConnection connection = null;
      private Topic topic = null;
      private TemporaryTopic tempTopic = null;
      private TopicSession pubSession = null;
      private TopicSession subSession = null;

      /**
      * Main to run the test.
      *
      * @param arg the command line arguments
      */
      public static void main(String [] args) {
      System.setProperty("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.provider.url", "localhost:1099");
      ReplyPublisher test = new ReplyPublisher();
      test.publish((new Date()).toString());
      System.exit(0);
      }

      /**
      * Creates the publisher.
      */
      public ReplyPublisher() {
      try {
      InitialContext jndi = new InitialContext();
      connectionFactory = (TopicConnectionFactory)jndi.lookup(
      "TopicConnectionFactory");
      connection = connectionFactory.createTopicConnection();
      pubSession = connection.createTopicSession(false,
      Session.AUTO_ACKNOWLEDGE);
      subSession = connection.createTopicSession(false,
      Session.AUTO_ACKNOWLEDGE);
      topic = (Topic)jndi.lookup("topic/testTopic");
      tempTopic = subSession.createTemporaryTopic();
      connection.start();
      } catch (Exception e) {
      System.err.println("ERROR: " + e.toString());
      }
      }

      /**
      * Send a message and wait for a reply.
      *
      * @param msg the text message
      */
      public void publish(String msg) {
      try {
      TextMessage message = pubSession.createTextMessage();
      message.setText(msg);
      System.out.println("publishing to topic: " + topic.getTopicName());
      TopicRequestor requestor = new TopicRequestor(subSession, topic);
      TextMessage returnMessage = (TextMessage)requestor.request(message);
      System.out.println("waiting for reply...");
      System.out.println("received: \"" + returnMessage.getText() + '\"');
      } catch (JMSException e) {
      System.err.println("ERROR: " + e.toString());
      }
      }
      }

        • 1. Re: JBoss 2.4.1 getJMSReplyTo() broken for request/reply
          David Martinez Newbie

          I have the same problem under JBoss 2.4.4. The lockup is kind of your fault. getJMSReplyTo() returns a destination, which should be a TemporaryTopic but it's actually a Topic. Since you are not catching exception on the onMessage, SpyMessageConsumer itself (who called onMessage) is catching the RuntimeException and eating it on line 493 (well, it actually log.warns(),but without e.toString() or stack trace).

          Change your getJMSReplyTo() line to read:


          Destination tempDestination = message.getJMSReplyTo();
          Topic tempTopic = (Topic)tempDestination;


          and it should go okay (at least it does under 2.4.4).


          Now, why is it creating Topic instead of TemporaryTopic? Does anybody know? Does it matter?

          Thanks,

          - David