0 Replies Latest reply on Jun 21, 2011 9:32 AM by Tim Coninx

    How to handle a Connection object to remote jms server

    Tim Coninx Newbie

      Hello,

       

      We are using an application that contains a jboss @Service mbean which encapsulates a javax.jms.Connection object.

       

      During startup of the mbean the connection is created by initializing a remote InitialContext, looking up the ConnectionFactory from that context, and creating a connection from that factory:

       

      @Service

      public class JMSPublisher extends etcc.... {

        private Connection connection;

        protected void startService() {

          Context ctx = getRemoteInitialContext();

          ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");

          connection = connectionFactory.createConnection();

        }

      }

       

      My question is: how long can we be supposed to maintain that connection ? In practise we see that the connection throws a JMSException when we try to create a session on it after an undefined amount of time.

       

      The documentation of Connection tells us that an object represents a socket, so timeouts due to inactivity could be normal. But how can we deal with it without creating new connections for each and every message ?

      Insert mo,