I am writing a JMS client that consumes from a Queue. My broker is activemq, if it matters.
One requirement is that the client should start even if the broker is down. In that case it should behave as if there where no messages in the Queue, and once the broker is up and messages start coming behave accordingly.
The problem is that in my code:
connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start()
If the broker is down, then it gets stuck in connection.start()
. While what I would like to have is connection.start()
to return silently and to continue to try to connect in the background and consume messages while it can and be silent when it can't.
How can I achieve this.