Is there a flag on RedisMqServer class that I can set to stop the instance of RedisMqServer picking messages off the queue?
Once a message is picked off the queue it is gone and I am hosting my "ProcessQueue" BasicAppHost within azure webjobs and of course it may get stopped (for example when I switch from staging).
I have warning of when the webjob will be shutdown ( http://blog.amitapple.com/post/2014/05/webjobs-graceful-shutdown/#.WCzhd8n74-1 ) and so if I could set this flag I could combine with a reasonable azure job 'stopping_wait_time' to allow all current service threads to finish.
Of course I know service threads could crash before fully handling the message, but I don't want to introduce Rabbit MQ.
(I would NOT want to stop the ability to publish as that would cause an issue if an executing service thread requires the publishing of another message)
If you just want to stop the
RedisMqServer or any MQ Server from processing messages you can just call
Thanks, I did see this and had a look but I wasn't sure 100% that it would not also kill any currently executing service threads. It won't right?
It stops all worker threads so they wont process any new messages, but it wont kill the currently executing background thread. But Starting the MQ Server again will kill any currently executing background thread, before starting a new one.
Are you saying if there are two or more different services executing in background threads only the one that is currently executing will run to completion and the others will be killed? (with async that could be lots killed). Or do you mean one per service can be 'current' in your definition?
No I'm saying each worker processing messages will stop processing new messages after calling
Stop(), they wont kill the single background that executes the message in each worker, but if
Start() was called before the background thread finished executing, it will be killed before start a new background thread for the worker.
Here's the relevant source code for MessageHandlerWorker.cs that does this.
Thanks, ideally I would also like to know if all the background threads attached to the workers are done so that I could wait for a little longer if not.
I see there is WorkerThreadsStatus() ...perhaps not ideal as it gives string with extra other rather than just int of the status...but I could just check if each contains 'stopped'.
Please can you confirm that would indeed tell me the background threads are done (or I misunderstand).
Stop() sets the status to
WorkerStatus.Stopping which tells the background thread not to process any more messages. Once the status of the MessageHandler is
WorkerStatus.Stopped it means the message worker's background thread finished.
GetStats() on each Worker Handler will return the status but the message workers are hard to get to. If you cast to
RedisMqServer you can get a text description of the Message worker status with WorkerThreadStatus() which you could check to see if they all contain the string "Stopped".