Home > Software design >  Apache ActiveMQ priorityBackup switching detection C#
Apache ActiveMQ priorityBackup switching detection C#

Time:01-28

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?

CodePudding user response:

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;
  • Related