Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suspend Mass Transit processing messages from the queue

Tags:

masstransit

I have a Mass Transit Service Bus that is listening to several queues and processing the messages. I would like to somehow pause the processing of new requests and wait for the current requests to complete so that I can run some housekeeping tasks.

A few of my own thoughts:

  • I have investigated the service bus BeforeConsumingMessage handler and although this would allow me to check for a 'Pause processing' flag in my database, I unsure how I would then actually pause the processing!
  • We are using RabbitMQ - could I use this to put the queues in a suspend state?
  • I have found so little on this subject that I wonder if it is an 'anti-pattern' and I should just stop my Mass Transit services if I want to run some housekeeping jobs and trust in any partially complete sagas to be picked up when the service bus starts back up. (Rather not go for this option, though).

So my question is: Is there a way to instruct the service bus to finish processing the current sagas but do not take any more messages from the queue?

like image 925
Mark Robinson Avatar asked Nov 26 '13 12:11

Mark Robinson


1 Answers

Cleanly shutting down a MT service will wait for any messages in process to completely finished. Why sometimes it takes a little while for a service to shutdown. Shutting down the service is the best way to handle this, you are sure MT is not pulling any new messages.

If your sagas are serialized to a backing store, e.g. NHibernate, then the state will be saved until the service is restarted and the sagas will pick up in the state they were left after the last message was processed. You should be in good shape. We do this all the time for any maintenance periods.

If you REALLY must leave the service running, call Dispose on the IServiceBus instance. This will do the same thing, letting the current consumers finish then releasing all your resources. Once you have done maintenance you can create a new IServiceBus instance as needed.

like image 126
Travis Avatar answered Nov 14 '22 10:11

Travis