Reputation: 155
I have a web app that uses Rebus with Azure Service Bus queues as a transport. It is configured with Simple Injector container.
During app disposal I want to stop rebus from accepting new messages and examine number of messages being handled at the moment. I may then decide to wait few seconds to allow handler to finish.
Is this achievable?
EDIT: I know about the existence of SetWorkerShutdownTimeout and Advanced.Workers.SetNumberOfWorkers methods. Could I achieve what I aim by calling Advanced.Workers.SetNumberOfWorkers(0)?
Upvotes: 4
Views: 347
Reputation: 18628
I may then decide to wait few seconds to allow handler to finish.
If you dispose the bus (or the container, which you always should do when your application shuts down, which in turn disposes the bus), any messages currently being handled will be given up to 30 seconds by default to finish processing.
No new messages will be received after the shutdown process is started.
Could I achieve what I aim by calling Advanced.Workers.SetNumberOfWorkers(0)?
Yes :) if you call
bus.Advanced.Workers.SetNumberOfWorkers(0);
worker threads will be removed, thus leading to no more messages being received.
But you should know, that simply disposing your SimpleInjector container will give all messages currently being handled a chance to finish.
Upvotes: 2