We have a Windows Service that has a Subscriber listening for messages from RabbitMQ. (It also publishes messages). When we stop the service, we want to stop processing new messages and allow all currently processing message threads to continue and finish processing (up to some timeout).
We tried this pattern:
OnStop()
{
Log("Pausing");
Subscriber.Pause();
// Wait for any messages to finish processing.
// Another option is to have a counter somehow keep track of the number of currently processing messages and wait for it to go to zero
Log("Waiting");
Thread.Sleep(10 * 1000);
Log("Disposing");
Subscriber.Dispose();
}
This seems to work, except we see this error in our log:
Pausing
NeuronEventLog Disconnecting party. Party DialIqServiceSubscriber, session 09ebb527-b27b-4e2d-bae7-d07302467826, server address net.tcp://localhost:50013/ESBTcpPubSub/, client address net.tcp://pc000185.office.leads360.com:61014/ESBTcpPubSubClient/09ebb527-b27b-4e2d-bae7-d07302467826, topic Infrastructure
ERROR NeuronEventLog Consume Messages: There was an error reported for the RabbitMQ channel for topic "DialerQueue": Thread was being aborted.
Inner Exception: Thread was being aborted.
Neuron.Esb.Channels.Amqp.AmqpChannelException: Consume Messages: There was an error reported for the RabbitMQ channel for topic "DialerQueue": Thread was being aborted. ---> System.Threading.ThreadAbortException: Thread was being aborted.
at Neuron.Esb.Channels.Amqp.AmqpChannel.ConsumeMessages()
--- End of inner exception stack trace ---
Waiting
Disposing
No matter what we try and what timing we use, we always get a thread was being aborted exception and in some cases we never finish processing our message handler threads.
Should we be using a different/better method?
We are using version 3.1.
Thanks in advance,
Dan
Tags:
when you refer to "stop processing new messages and allow all currently processing message threads to continue and finish processing", are you referring the threads within the windows service, or processing you're doing within the OnReceive event?
if you throw an error within the onreceive event, the message will be rolled back to the underlying rabbit MQ queue. I believe Pause does the disconnect. but throwing the threadAbortException is a bug that we can fix. Please send a support request to NeuronSupport@neudesic.com. This will open a ticket and we can fix.
Thanks
Hi Marty,
Thanks for replying (I just also sent an email to your support regarding this question).
What we want is to be able to cleanly shut down the Windows Service instance (for example when we want to deploy a new version). In order to do this, we want to be able to stop receiving new messages on this service instance. But we don't want to abort any OnReceive threads that are currently executing (unless they take too long).
Dan
Neuron ESB Product Support Forums and Communities
© 2024 Created by Neuron Admin. Powered by