Reputation: 47
I am using activeMQ 5.4 for JMS implementation in my project. I want to notify user every time application fails to send a message but I am not getting any handle at occurrence of an exception. For instance, In case JMS broker is down and I perform a create connection, session etc. or a message send operation within a try block, control never comes back to catch block or ExceptionListener set for the connection. My code looks like:
connection = (TopicConnection) (new ActiveMQConnectionFactory(localBrokerURL)).createConnection();
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException arg0) {
System.out.println("Exception Occurred");
}
});
connection.start();
final TopicSession session =conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
final Topic sendTopic = session.createTopic("someTopicName");
where Value of localBrokerURL is
failover://(ssl://localhost:61618?trace=true&wireFormat.maxInactivityDuration=0)
Please help. Any hint is highly appreciated.
Upvotes: 0
Views: 1273
Reputation: 21015
just set the timeout
property on the connection URI and it will throw an error instead of block the thread...
failover://(ssl://localhost:61618?trace=true&wireFormat.maxInactivityDuration=0)?timeout=10000
see http://activemq.apache.org/failover-transport-reference.html
Upvotes: 0
Reputation: 556
that is the intent of the failover: transport. It will hide transport failures and automatically try and reconnect, replaying any jms state when a new connection is established. There is a transportListener that you can use to get transport suspended and resumed events. If you remove the failover: component from the broker url, you will get all exceptions propagated up to your client.
Upvotes: 3