3 Replies Latest reply on Nov 29, 2011 9:29 AM by Andy Taylor

    Setting connection time out on Message Producer

    Abbas Raza Newbie



      I have a message producer client in a JMS fashion. It publishes messages to a topic on HornetQ servers. Is there a way to set a timeout so that:


      1. getting a connection does not hang on for ever.

      2. message producer does not hang for ever.


      For both the cases, it is assumed that there is an issue with HornetQ server.


      Here is an extract of the code.


        private static Context context;

        private static Connection connection;

        private static Session session;


          Properties props = new Properties();

          props.put(Context.PROVIDER_URL, PROVIDER_URL);

          props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

          props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");


          context = new InitialContext(props);


          ConnectionFactory connFactory = (ConnectionFactory) context.lookup("/ConnectionFactory");

          connection = connFactory.createConnection();

          session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);



          topic = (Topic) context.lookup(<MY_TOPIC>);

          producer = (MessageProducer) session.createProducer(topic);

          message = session.createTextMessage(eventInfo);



      Apologies if this has been covered earlier. Appreciate any help.