AspNetCore.HealthChecks.Rabbitmq 9.0.0
RabbitMQ Health Check
This health check verifies the ability to communicate with a RabbitMQ server
Example Usage
With all of the following examples, you can additionally add the following parameters:
name
: The health check name. Default if not specified israbbitmq
.failureStatus
: TheHealthStatus
that should be reported when the health check fails. Default isHealthStatus.Unhealthy
.tags
: A list of tags that can be used to filter sets of health checks.timeout
: ASystem.TimeSpan
representing the timeout of the check.
Dependency Injected IConnection
As per RabbitMQ docs and its suggestions on high connectivity churn, connections are meant to be long lived. Ideally, this should be configured as a singleton. The health check should use the same IConnection instance that is used in the application.
public void ConfigureServices(IServiceCollection services)
{
services
.AddSingleton<IConnection>(sp =>
{
var factory = new ConnectionFactory
{
Uri = new Uri("amqps://user:pass@host/vhost"),
};
return factory.CreateConnectionAsync().GetAwaiter().GetResult();
})
.AddHealthChecks()
.AddRabbitMQ();
}
Caching IConnection outside of Dependency Injection
Alternatively, you can create the connection outside of the dependency injection container and use it in the health check.
public void ConfigureServices(IServiceCollection services)
{
services
.AddHealthChecks()
.AddRabbitMQ(sp => connectionTask.Value);
}
private static readonly Lazy<Task<IConnection>> connectionTask = new Lazy<Task<IConnection>>(CreateConnection);
private static async Task<IConnection> CreateConnection()
{
var factory = new ConnectionFactory
{
Uri = new Uri("amqps://user:pass@host/vhost"),
};
return await factory.CreateConnectionAsync();
}
Breaking changes
RabbitMQHealthCheck
was letting the users specify how IConnection
should be created (from raw connection string or from Uri
or from IConnectionFactory
), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and it's the caller responsibility to provide the instance of IConnection
(please see #2048 for more details). Since RabbitMQ recommends reusing client instances since they can be expensive to create, it's recommended to register a singleton factory method for IConnection
. So the client is created only when needed and once per whole application lifetime.
No packages depend on AspNetCore.HealthChecks.Rabbitmq.
.NET 8.0
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- RabbitMQ.Client (>= 7.0.0)
.NET Standard 2.0
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- RabbitMQ.Client (>= 7.0.0)
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 1 | 1/18/2025 |
8.0.2 | 0 | 9/3/2024 |
8.0.1 | 0 | 4/2/2024 |
8.0.0 | 0 | 12/15/2023 |
7.0.0 | 0 | 7/30/2023 |
7.0.0-rc2.7 | 0 | 3/13/2023 |
7.0.0-rc2.6 | 0 | 1/14/2023 |
7.0.0-rc2.5 | 0 | 12/27/2022 |
7.0.0-rc2.4 | 0 | 12/27/2022 |
6.0.2 | 0 | 2/28/2022 |
6.0.1 | 0 | 12/29/2021 |
6.0.1-rc2.3 | 0 | 11/10/2021 |
6.0.1-rc1.1 | 0 | 11/5/2021 |
6.0.0 | 0 | 12/29/2021 |
5.0.2 | 0 | 11/4/2021 |
5.0.1 | 0 | 1/5/2021 |
5.0.0 | 0 | 12/29/2020 |
5.0.0-preview1 | 0 | 11/22/2020 |
3.1.4 | 0 | 7/22/2020 |
3.1.3 | 0 | 7/22/2020 |
3.1.2 | 1 | 11/9/2024 |
3.1.1 | 0 | 4/17/2020 |
3.1.0 | 0 | 4/9/2020 |
3.0.7 | 0 | 4/1/2020 |
3.0.6 | 0 | 3/31/2020 |
3.0.5 | 0 | 2/11/2020 |
3.0.4 | 0 | 1/20/2020 |
3.0.3 | 0 | 12/5/2019 |
3.0.2 | 0 | 12/2/2019 |
3.0.1 | 0 | 10/30/2019 |
3.0.0 | 0 | 9/24/2019 |
2.2.1 | 0 | 2/25/2019 |
2.2.0 | 0 | 11/14/2018 |