ActiveMQ Fail-over: how to detect when application starts and cannot find broker

I am using ActiveMQ fail-over for example.

failover:(tcp://host1:61616,tcp://host2:61616)

      

I would like to alert when neither host1 nor host2 is available.

If the application is already connected to the broker, you can detect when it crashes through the TransportListener. The same is not possible with the initial connection. It will just hang, repeating each broker. This is the desired behavior in which I want it to keep trying to connect, however I also want to be notified that it is having problems so I can alert and someone can look into it.

One solution is to use

failover:(tcp://host1:61616,tcp://host2:61616)?startupMaxReconnectAttempts=1

      

This means it will try every host and then throw an exception that my application can handle to alert it and then try to connect again. This is not ideal as my application then has to effectively duplicate ActiveMQ reconnect logic.

Is there a better way to detect broker problems on initial connection?

+3


source to share


1 answer


Short answer: no, there is no way to know from a client (application) launch perspective.

Long answer. As an application, you will only know when: you have no brokerage at all (via startupMaxReconnectAttempts) or when switching from one broker to another. This is the expected and desired behavior, since the whole point of the failover mechanism is to hide it all from the consumer.



There might be some ways (using a dynamic network of brokers , but this will require more logic than the solution you suggest.

I would think that you are trying to fix the problem with the wrong tool: using a failover mechanism (with maximum reconnect and proper timeout) will just provide you with a notification when something goes wrong (no broker at all). The "health" or "connection" of other brokers needs a separate mechanism (at the system level - use a monitoring tool or at the application level - create a small mechanism to support all brokers in the uri list)

+3


source







All Articles