1 Reply Latest reply on Oct 11, 2006 3:36 AM by Janos Biro

    Topic/QueueRequestor does not respond

    Janos Biro Newbie

      Hi all,

      I'm not completely sure that it is new problem, but I've not found the solution yet in JBoss forum...

      I'm using a stateless session bean which uses

      TopicRequestor.request
      to publish a message into a Topic and wait for the response. The subscriber of the target topic is a simple MDB.
      This MDB receives the message and sends the answer back to the TemporaryTopic specified in the JMSReplyTo field correctly without throwing any exception, but the
      TopicRequestor.request
      hangs and does not receive any reply.
      I reimplemented the TopicRequestor because I would need timeout feature in any case, but it has also the same problem. Is the temporaryQueue/Topic working in JBoss at all?

      JBoss: 4.0.4 GA
      Op. : Windows XP


      My caller code which using TopicRequestor (HANGS):

      //The STopicRequestor is my implementation, but the behaviour (except timeout handling of course) and error symptoms are the same

      //Create a requestor using the session
       STopicRequestor requestor = new STopicRequestor(session,triggerTopic);
      
       //creating a trigger message
       TextMessage trigger = session.createTextMessage();
       trigger.setText("Trigger message SYNC");
      
       //sending message and waiting for the reply
       System.out.print("Sending sync trigger to the topic and waiting the response...");
      
       TextMessage replyMessage = (TextMessage) requestor.request(trigger,10000);
       System.out.print("Sending sync trigger to the topic and waiting the response...done");
       requestor.close();
      


      The STopicRequestor implementation (WORKING):

      public class STopicRequestor {
      
       private final TopicSession targetSession;
      
       private final TemporaryTopic callbackTopic;
      
       private final TopicPublisher publisher;
       private final TopicSubscriber subscriber;
      
       /**
       *
       * @param targetSession TopicSession (initialized) to be used
       * @param targetTopic Topic (intitialized) to be used
       * @throws JMSException Thrown in case of internal JMS error
       */
       public STopicRequestor(TopicSession targetSession, Topic targetTopic) throws JMSException
       {
       this.targetSession = targetSession;
      
       callbackTopic = targetSession.createTemporaryTopic();
       publisher = targetSession.createPublisher(targetTopic);
       subscriber = targetSession.createSubscriber(callbackTopic);
       }
      
      
       /**
       * Blocks the caller till the reply received or timeout expires
       * @param messageToBeSent The message to be sent to the Topic
       * @param timeoutMilliseconds If set to 0 no timeout is used
       * @return The reply message, null is returned if timeout expired
       * @throws JMSException Thrown in case of internal JMS error
       */
       public Message request(Message messageToBeSent, long timeoutMilliseconds) throws JMSException
       {
       Message replyMessage = null;
      
       messageToBeSent.setJMSReplyTo(callbackTopic);
      
       publisher.publish(messageToBeSent);
      
       replyMessage = subscriber.receive(timeoutMilliseconds);
      
       return replyMessage;
       }
      
       public void close() throws JMSException
       {
       targetSession.close();
       callbackTopic.delete();
       }
      
      }


      The MDB Code which consumes the message (WORKING)

      /
      /Create a connection to JMS Provider
       TopicConnection connection = factory.createTopicConnection();
      
       //Create a session which is a helper class during communication
       //no transaction is needed, second parameter is meaningless in case of publishing
       TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      
       //Create a publisher using the session
       TopicPublisher publisher = session.createPublisher(callback);
      
       //creating the response
       TextMessage response = session.createTextMessage();
       response.setText("Synchronous response");
      
       System.out.print("Sending response to temporary topic..." + publisher.toString());
       //sending message
       publisher.publish(response);
      
       System.out.print("Sending response to temporary topic...done");
      
       publisher.close();


      I have seen in the specification that a TemporaryQueue/Topic can be consumed only using the same Session that created it before. But how coul I pass a Session to the MDB? I'm a little bit confused by the spec. and some examples.

      Could you help me and propose a working solution?
      Thanks a lot for your help in advance,

      Bye,
      Janos Biro
      janos.biro@siemens.com