I want to create a java class , which has the sole purpose of checking the status of an ActiveMQ broker (or connectivity to an ActiveMQ broker as an outage may be defined as the client losing network connectivity as well).
so basically there would be a thread running after every few seconds to check the status of the broker and if there broker is down, I want to do some specific task of mailing the support group and stuff like that.
The examples online are not detailed enough to explain how the above can be achieved.
Has someone already done this, or can suggest a nice way to make this happen??
Thanks, Neeraj
The following will also work to check if ActiveMQ is up and running:
try {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
// set transport listener so that active MQ start is notified.
factory.setTransportListener(transportListenerObject);
Connection connection = factory.createConnection();
// This will throw error if activeMQ is not running.
connection.setClientID("my_client_id");
} catch (JMSException ex) {
if (ex.getLinkedException() instanceof IOException) {
// ActiveMQ is not running. Do some logic here.
// use the TransportListener to restart the activeMQ connection
// when activeMQ comes back up.
} else {
// Something seriously went wrong with the factory or connection
// creation. Abort the process here, as nothing can be done.
// Log the error and troubleshoot.
}
}