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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With