What if I don't close Service Bus Queue Client and the process stops?

5/21/2020

I m trying to deploy a never ending message pump to process service bus queue messages as a .NET Core console app on Azure AKS Kubernetes.

The app will have auto-scaling based on the number of message in the queue, so more app may be deployed and when started they will connect to the service bus and start RegisterMessageHandler.

The auto-scaler may also teardown the app but without an event to signal the shutdown to the Console app I won't be able to close the queue properly to stop receiving messages or stop processing messages.

How does one handle that in .NET Core on AKS?

-- fred_
.net-core
asp.net-core
azure-aks
azureservicebus
kubernetes

1 Answer

5/21/2020

There are two signals available on Pod shutdown. The PreStop hook can be configured to trigger a shell command or generate an HTTP request against your container. You should also expect your running process to receive a TERM signal prior to the pod stopping.

Here's a blog post which covers some basics on hooking the TERM signal by implementing IApplicationLifetime within the context of a Kestrel server.

This article has a thorough end-to-end example of a simple implementation of IApplicationLifetime.

For .NET 3.x, IHostApplicationLifetime supersedes IApplicationLifetime.

-- bpdohall
Source: StackOverflow