1 Reply Latest reply on Oct 28, 2003 2:39 AM by adrian.brock

    Application hangs on createTopicSession

    fympmul

      I've got an application that registers a message listener to a JMS topic on the JBoss server. After some time (usually a few hours), when users start up a new instance of the application, the app hangs on the call to topicConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE). Messages get published to the topic from a stateless session bean on the JBoss Server. Any clue as to what is the matter?

      Here's the client code:

      private void registerListener()
      {
      try
      {
      // Get the initial context
      Context context = InitialContextSingleton.getInitialContext();

      // Get the connection factory
      TopicConnectionFactory topicFactory =
      (TopicConnectionFactory)context.lookup(factoryName);

      // Create the connection
      topicConnection = topicFactory.createTopicConnection();

      // Create the session
      topicSession = topicConnection.createTopicSession
      (true, Session.AUTO_ACKNOWLEDGE);

      // Create a subscriber
      topicSubscriber = topicSession.createSubscriber
      ((Topic)context.lookup("topic/SkewUpdate"), null, false);

      // Set the message listener, which is this class since we implement
      // the MessageListener interface
      topicSubscriber.setMessageListener(this);

      logger.info("Subscribed to topic: " + topicName);

      // OBS! For the message listener to receive any messages the
      // connection has to be started
      topicConnection.start();
      }
      catch (NamingException ex)
      {
      logger.error("Unable to register listener", ex);
      }
      catch (JMSException ex)
      {
      logger.error("Unable to register listener", ex);
      }
      catch (Exception ex)
      {
      logger.error("Unable to register listener", ex);
      }
      }


      Here's the server code that sets up the session on the publisher's side:

      public void ejbCreate()
      {
      try
      {
      // Get the initial context
      Context context = new InitialContext();

      // Get the connection factory
      TopicConnectionFactory topicFactory =
      (TopicConnectionFactory)context.lookup("ConnectionFactory");

      // Create the connection
      topicConnection = topicFactory.createTopicConnection();

      // Create the session
      topicSession = topicConnection.createTopicSession
      (false, Session.AUTO_ACKNOWLEDGE);

      // Look up the destination(s)
      skewUpdateTopic = (Topic)context.lookup("topic/SkewUpdate");

      topicConnection.start();
      }
      catch (NamingException ex)
      {
      logger.error("NamingException: "+ex.getMessage());
      }
      catch (JMSException ex)
      {
      logger.error("JMSException: "+ex.getMessage());
      }
      }


      And here's the code that actually sends the message to the topic from the EJB:

      private void sendSkewUpdate(String msg)
      {
      TopicPublisher publisher = null;

      try
      {
      // Create a message
      log("Creating message:");
      TextMessage message = topicSession.createTextMessage();
      log(msg);
      message.setText(msg);

      log("Creating publisher for topic topic/SkewUpdate");
      // Create a publisher
      publisher = topicSession.createPublisher(skewUpdateTopic);

      // Publish the message
      publisher.publish(message);
      log("Published message");
      }
      catch (JMSException ex)
      {
      log("JMSException: "+ex.getMessage());
      }
      finally
      {
      try
      {
      if (publisher != null)
      // Free up resources
      publisher.close();
      log("Publisher for topic topic topic/SkewUpdate closed");
      }
      catch (JMSException ex)
      {
      // What to do when closing the publisher fails?
      log("Closing publisher failed: " + ex.getMessage());
      }
      log("-sendSkewUpdate");
      }
      }