Cannot monitor Failover Transport

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot monitor Failover Transport

filiphr
Hi,

I already created a JIRA  AMQ-6860
<https://issues.apache.org/jira/browse/AMQ-6860>   for this, but I was
redirected to the forum.

When adding a TransportListener as described in  How can I monitor the
connection with the broker
<http://activemq.apache.org/how-can-i-monitor-the-connection-with-the-broker.html>
, using a default failover settings and the broker being down nothing is
being sent to the listener. Is this an expected behaviour?

How can one monitor when the failover transport is not being able to
connect? Apart from looking into the warning message into the logs?

Thank you in advance,
Filip



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Reply | Threaded
Open this post in threaded view
|

Re: Cannot monitor Failover Transport

art.licis
Hi Filip,

First of all, you should share more details on your setup. Is it just one
broker listed within failover:(..), or more than one? Are you sure you are
registering your TransportListener properly on a client side? If you have
more than one broker for failover, and you connect to the first one, but
kill the second one, you won't get any notifications as non-connected
brokers are not monitored.

Another case you might be referencing: on initial connection attempt no
brokers available. I've double checked this and can confirm no notifications
are sent (well, TransportListener's method signatures on their own don't
speak about initial connection). In this case, you can do the following:

1) create a connection, add transport listener as needed
2) in a separate thread, monitor connection state by calling
connection#isStarted(). It will be false until the connection is
established.

Code snippet:


ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61617)");
final ActiveMQConnection connection = (ActiveMQConnection)
connectionFactory.createConnection();
connection.addTransportListener(new TransportListener() {
   public void onCommand(Object o) { System.out.println("OnCommand: " + o);
}
   public void onException(IOException e) { e.printStackTrace(); }
   public void transportInterupted() { System.out.println("Interrupted"); }
   public void transportResumed() { System.out.println("Resumed"); }
});

new Thread(new Runnable() {
   public void run() {
      while(true) {
         System.out.println("Connection started? : " +
connection.isStarted());
         try {
            Thread.sleep(1000);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
   }
}).start();

connection.start();



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Reply | Threaded
Open this post in threaded view
|

Re: Cannot monitor Failover Transport

filiphr
Hi,Sorry for not being more specific. I have created an example with my
setup. You can find it  here
<https://github.com/filiphr/activemq-boot-jms-health/tree/master>  . It is a
simple spring boot application where the broker url is set to 2 failover
addresses (no ActiveMQ needs to run to see the issue).The TransportListener
is registered with the properly (I think).The issue I am experiencing is not
when a broker goes down, but when no broker is available during startup.I
know that the TransportListener method signatures don't speak about initial
connection, but I thought that monitoring the broker means monitoring
everything, not after initial connection.According to your snippet, the only
way to monitor the broker in a Spring Boot Actuator endpoint is to start the
connection in a separate Thread and check if it has been connected. There is
no other way to achieve this?Cheers,Filip



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html