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;
Related
This question is basically the same as 1 but instead Grpc.Core I would use the more up to date library Grpc.Net.Client. The Channel class here has neither a property "State" nor a ConnectAsync() method nor any other method to detect the current connection state. My goal is to write a Server and a Client application where the startup order ist arbitrary, i.e. If the Client is started before the Server it shall wait until the Server and therefore the connection becomes ready.
I have a scaled out application, where each instance connects to a azure service bus subscription with the same name. The end result being that only a single instance gets to act on any given message because they are all listening to the same subscription.
Occasionally the application needs to place an instance into an idle state (service fabric ActiveSecondary replica). When this occurs, I need to close the subscription so that this instance no longer receives messages. If there were 2 instances originally, once one gets placed into the idle state all message should go to the remaining instance. This is important so that all messages are handled by a properly configured primary instance.
When the instance becomes idle, a cancellation token is cancelled. I have code listening for the cancellation and calling Close() on the SubscriptionClient generated when I created the subscription originally.
The issue is, even after I call Close() on one instance, messages are still being randomly split between it and the primary.
Is the way I'm doing this inherently wrong, or is something else in my code causing this behavior?
The Azure Service Bus track 0 and 1 SDKs do not support CancellationTokens. If you're closing your client and messages won't be processed, they'd be picked up another competing instance when visible again. That's where MaxLockDuration and MaxDeliveryCount are important to ensure messages have enough processing attempts to account the situation you're describing w/o waiting for too long.
Disregard this post. Turns out I had the same subscription name used twice within a single instance, so they were competing for the events. The close() function works as expected.
As per the RabbitMq java client API, https://www.rabbitmq.com/api-guide.html#recovery
Unhandled exceptions related to connection, channel, recovery and
consumer lifecycle are delegated to the exception handler. Exception
handler is any object that implements the ExceptionHandler interface.
By default, an instance of DefaultExceptionHandler is used. It prints
exception details to the standard output.
It is possible to override the handler using
ConnectionFactory#setExceptionHandler. It will be used for all
connections created by the factory:
we have
ConnectionFactory factory = new ConnectionFactory();
cf.setExceptionHandler(customHandler);
What is the same implementation for .NET RabbitMq client? Adding this code is still writing console logs and not executing my logic and How do I remove the existing event handler?
var factory = new ConnectionFactory() { HostName = "localhost" };
var connection = factory.CreateConnection();
connection.CallbackException += (x, y) => {
Console.WriteLine("Handled"); // not printing
};
I would like to override/remove the logs which are printing to console because of topologyrecoveryexception.
Could anyone help me on how to override this default behavior of logs to console by RabbitMq.Client using v4.1. Any help is greatly appreciated.
First you should upgrade to the latest 5.X .NET client.
Then, notice in the ChangeLog file that console logging was replaced by event source (link).
CallbackException is used when one of your callbacks raises an exception, I believe. It has nothing to do with exceptions generated by the library.
NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.
I need send a custom windows message with a custom Id that another application will listen for.
Is there any predefined range of message Id ' s that Windows reserve for internal messages, such as SQL Server does (up to 50.000 for Internal messages)?
The documentation says:
Application-Defined Messages
An application can create messages to be used by its own windows or to communicate with windows in other processes. If an application creates its own messages, the window procedure that receives them must interpret the messages and provide appropriate processing.
Message-identifier values are used as follows:
The system reserves message-identifier values in the range 0x0000 through 0x03FF (the value of WM_USER – 1) for system-defined messages. Applications cannot use these values for private messages.
Values in the range 0x0400 (the value of WM_USER) through 0x7FFF are available for message identifiers for private window classes.
If your application is marked version 4.0, you can use message-identifier values in the range 0x8000 (WM_APP) through 0xBFFF for private messages.
The system returns a message identifier in the range 0xC000 through 0xFFFF when an application calls the RegisterWindowMessage function to register a message. The message identifier returned by this function is guaranteed to be unique throughout the system. Use of this function prevents conflicts that can arise if other applications use the same message identifier for different purposes.
I suspect that RegisterWindowMessage is the right choice for you.
I am in the process of QuickFix service initiator implementation in c# which needs to do the following.
Listen to incoming QuoteRequest messages and save them to a local database/queue.
Our users will have the ability to hit the Bids on these quote requests. These selections will be saved in a local queue.
Service will need to read the queue and send Quote messages back to the sender.
Listen to QuoteResponse / BusinessReject and QuoteStatus Messages from the sender and store on our end.
I'm planning to have two threads in my service.
Thread 1: This will be used to listen to incoming QuoteRequest, Quote response, Businessreject and quotestatus messages.
Outgoing ExecutionReport will be sent from OnMessage event handler while cracking QuoteResponse message.
Those messages will get stored in our system and published on our sites/queue etc.
Thread 2: This will listen to another local queue and sends out Quote(bids) messages to the acceptor. Quotes will be sent out using Session.SendToTarget.
Is there a way to configure two instances of initiators to be used in each thread ? Or do I create one initiator and add two sessions.
Would it work if both initiators are using same socket server and port ? Also if a message is not cracked by one thread would it be available for the other thread ?
I couldnt find any example of a multithreaded approach to handle both incoming and outgoing messages.
Appreciate any inputs/recommendation on a correct approach to implementation.
This is only one connection, and only one session, so there should only be one Initiator.
You can set up different worker threads, but your various OnMessage() callbacks should be a common entry point. They can dispatch their received messages to your thread (you could have them push received messages into a queue or something for your threads to consume). Your threads can do what they need to do and then call sendToTarget as appropriate.
Above all else, try not to put any expensive logic in the QF callbacks; put it in the threads. Other than that, you can do what you want.