Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recognize ActiveMQ disconnect using NMS and C#

Tags:

activemq

I have a C# publisher and subscriber that talk to each other using ActiveMQ and NMS. Everything works fine, except I have no way to know when ActiveMQ goes down. This is particularly bad for the consumer. They stop getting data, but aside from the fact that data stops showing up, no errors or events are raised.

Is there a way using NMS(particulary Apache.NMS.IConnection or the Apache.NMS.ISession objects)

I downloaded the implementation that I'm using from Spring, but I'm not using any specific spring implementations, everything I'm using is in the Apache.NMS and Apache.NMS.ActiveMQ namespaces.

like image 422
Jonathan Beerhalter Avatar asked Oct 14 '22 11:10

Jonathan Beerhalter


1 Answers

Well, it's been a lot since this question has been asked, but now you have several events available:

m_connection.ConnectionInterruptedListener += new ConnectionInterruptedListener(OnConnectionInterruptedListener);
m_connection.ConnectionResumedListener += new ConnectionResumedListener(OnConnectionResumedListener);
m_connection.ExceptionListener += new ExceptionListener(OnExceptionListener);

where m_connection is a IConnection object.

With these 3 events you will be able to find when your broker is down (among other usefull information, such as when it resumes the connection or when he encounters an exception)

Note: If you are in failover mode, these exceptions will be swallowed by the failover transport layer and handled automatically with them. Hence you will not receive any of these events.

like image 62
srodriguez Avatar answered Oct 18 '22 14:10

srodriguez