Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveMQ createSession timeout

Is there any way of setting a timeout when creating a session Object from a ActiveMQ connection?

The code I'm using looks as follows:

ConnectionFactory factory = Settings.getJmsConnectionFactory(ip);
connection = factory.createConnection();
// insert timeout here
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(Settings.Topic);
MessageConsumer consumer = session.createConsumer(topic);
consumer.setMessageListener(this);
connection.start();

This works fine as long as the message server is already launched. Otherwise the createSession call will block. I could execute it on another thread to avoid the application from blocking, but I thought I'd ask to find out whether there's a "cleaner" way of doing it.

like image 270
Max Avatar asked Nov 04 '22 17:11

Max


1 Answers

Are you sure it's on the createSession() call? If the server isn't available, it should fail on createConnection(). If you don't have a server running, and you're using the failover transport, it'll try to reconnect forever using the default settings. Look at the transport options for the failover transport for how you can fix it.

like image 182
Ryan Stewart Avatar answered Nov 09 '22 05:11

Ryan Stewart