1

I am currently using NMS (C#), and I provide it with three server addresses with a priority server with the expectation for it to connect to the 2nd or 3rd server when the main is offline and then re-connect with the main server once back online.

I am using the following nugets:

  • Apache.NMS.ActiveMQ (1.8.0)
  • Apache.NMS (1.8.0)
  • Broker version 5.16.4 (I think)

Connection string:

failover:(tcp://mainServer:61619,tcp://backup1:61619,tcp://backup2:61619)?randomize=false&timeout=10000&backup=true&priorityBackup=true&useExponentialBackOff=true&reconnectDelayExponent=2.0&initialReconnectDelay=5000&initialReconnectDelay=180000&consumerExpiryCheckEnabled=false

When the main server goes offline, I expect it to trigger an event to state that it is switching. Is there any way to detect when it switches back and forth between servers?

Liam
  • 439
  • 1
  • 4
  • 26

1 Answers1

1

I'm guessing that you haven't bothered to look at the actual NMS.API source as the answers are all there. The IConnection has events for what you are looking to accomplish:

/// <summary>
/// A delegate that is used by Fault tolerant NMS Implementation to notify their
/// clients that the Connection is not currently active to due some error.
/// </summary>
public delegate void ConnectionInterruptedListener();

/// <summary>
/// A delegate that is used by Fault tolerant NMS Implementation to notify their
/// clients that the Connection that was interrupted has now been restored.
/// </summary>
public delegate void ConnectionResumedListener();

And:

    /// <summary>
    /// An asynchronous listener that is notified when a Fault tolerant connection
    /// has been interrupted.
    /// </summary>
    event ConnectionInterruptedListener ConnectionInterruptedListener;

    /// <summary>
    /// An asynchronous listener that is notified when a Fault tolerant connection
    /// has been resumed.
    /// </summary>
    event ConnectionResumedListener ConnectionResumedListener;
Tim Bish
  • 17,475
  • 4
  • 32
  • 42
  • I have those implemented, but I do not know if they trigger when it switches server. – Liam Jan 27 '23 at 21:23
  • That is the intent, you can of course test it to be sure. – Tim Bish Jan 27 '23 at 21:24
  • I will update this post when I can confirm it. Thank you for the assistance. – Liam Jan 27 '23 at 21:27
  • 1
    The Unit tests for NMS.ActiveMQ can also enlighten you on the working of the client, and would seem to validate that this is how the events are fired. – Tim Bish Jan 27 '23 at 21:32
  • I blocked the IP address of the main server and it did trigger the interrupt. I have unblocked the IP address and unfortunately didn't switch back to the primary, so I will have to implement that. – Liam Jan 27 '23 at 21:40
  • 1
    Failover in ActiveMQ clients doesn't work that way, there is no primary only "the one you are connected to now" – Tim Bish Jan 27 '23 at 22:08