简体   繁体   中英

Apache ActiveMQ priorityBackup switching detection C#

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM