Open mksergiy opened 11 months ago
Hmm actually this might call for giving Rebus the ability to wait for currently executing message handlers to finish - this way, the stopping token above could just set the number of workers to 0 (thus preventing that additional messages are fetched), and then block, waiting for currently executing message handlers to finish.
This bus could then be disposed at a later point in time when everything else has shut down.
I'll run a couple of experiments to see if that would be feasible.
Registering bus.Dispose() in IHostApplicationLifetime.ApplicationStopping causes the bus to be disposed before the generic host stops the hosted services
code from RebusInitializer:
When I commented out the registration mentioned above, everything worked fine, including the order of stopping RebusBackgroundService.