Is there a way to tell the host to stop picking up messages from the queue? Or is there a hook in the service bus extension we can use to stop messages from being picked up?
There are two use cases I can think of. Graceful shutdown and also if we detect our database is unavailable. If the DB is unavailable there's no point trying to process messages, but if we can't tell it to stop picking up messages then all those messages will end up in the DLQ, even though they are most likely perfectly valid.
We use a ServiceBusTrigger
and in our startup code we call host.UseServiceBus()
, this nicely automatically picks up messages from the queue.
If we call host.Stop()
, then it obviously stops picking up messages from the queue. Unfortunately it also stops all processing that may be in progress. We want to ensure any in progress processing completes before calling stop.