I have a .Net service that functions as a bridge between RabbitMQ and another service. Messages are received and forwarded; Replies are received and delivered to RabbitMQ. Internally I have some queues for buffering.
I now want to assume more control over the shutdown process of my bridge.
Once the shutdown signal is received, the service should:
- Stop subscribing to events from RabbitMQ
- Process all events in my queues
- shutdown
The challenge is that processing an event in my inbox, may trigger a new reply, which should be put into my outbox and delivered, before shutting down.
The Kestrel problem
Kestrel seems to listen to the IHostApplicationLifetime.ApplicationStopping token, and when this is triggered, it will stop accepting new requests.
I need to override this behaviour, and allow it to continue to process events, while I empty my queues.
I have been unable to find any way to alter the default behaviour of Kestrel.
I am hoping to find some hints, tricks or links to documentation.
Steps sofar
I have looked around the documentation and intellisence for ways to override the default Kestrel behaviour.
I cannot find any options or settings to change this.
I need a way to override or inject my own CancellationToken in Kestrel, so I can control the shutdown process.