asp.net-core.net-coreasp.net-core-2.2asp.net-core-middleware.net-core-2.2

Use health check middleware in .NET Core Generic Host


Using the .NET Core Generic Host for an application that processes async messages.

The reason we're using the generic host instead of the .NET Core WebHost is because one of my colleagues had seen a few occasions where MassTransit (the light weight service bus framework that we're using) running as part of a .NET Core WebHost was not always shutting down gracefully on Linux after receiving a SIGTERM signal - we had to use SIGKILL to forcibly kill the process.

This application will run on Kubernetes and we want to implement a self-healing architecture using K8s liveness probes. In other .NET Core applications that use WebHost, we've used Health Checks that were introduced in .NET Core 2.2, but I don't know how to use middleware like this in a generic host.

In a WebHost I can configure the middleware as follows:

app.UseHealthChecks(appSettings.HealthChecksPath ?? "/health");

How would I go about doing this if using .NET Core Generic Host...

Kind regards.


Solution

  • Solved this by using a HttpListener based health-check server - happy to be proven wrong, but AFAIK, Kestrel / ASP.NET Core middleware is not suitable for .NET 2.2 & generic host.

    see here for code.