AspNetCore.HealthChecks.Rabbitmq 8.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.
Basic
This will create a new IConnection
and reuse on every request to get the health check result. Use
the extension method where you provide the Uri
to connect with. You can optionally set the SslOption
if needed.
IConnection created with this option use UseBackgroundThreadsForIO by default in order to gracefully shutdown on non reference IConnection by ServiceCollection.
public void ConfigureServices(IServiceCollection services)
{
services
.AddHealthChecks()
.AddRabbitMQ(rabbitConnectionString: "amqps://user:pass@host1/vhost")
.AddRabbitMQ(rabbitConnectionString: "amqps://user:pass@host2/vhost");
}
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.
If you are sharing a single connection for every time a health check is requested, you must ensure automatic recovery is enable so that the connection can be re-established if lost.
public void ConfigureServices(IServiceCollection services)
{
services
.AddSingleton<IConnection>(sp =>
{
var factory = new ConnectionFactory
{
Uri = new Uri("amqps://user:pass@host/vhost"),
AutomaticRecoveryEnabled = true
};
return factory.CreateConnection();
})
.AddHealthChecks()
.AddRabbitMQ();
}
Alternatively, you can specify the connection to use with a factory function given the IServiceProvider
.
public void ConfigureServices(IServiceCollection services)
{
services
.AddHealthChecks()
.AddRabbitMQ(sp =>
{
var factory = new ConnectionFactory
{
Uri = new Uri("amqps://user:pass@host/vhost"),
AutomaticRecoveryEnabled = true
};
return factory.CreateConnection();
});
}
Or you register IConnectionFactory and then the healthcheck will create a single connection for that one.
public void ConfigureServices(IServiceCollection services)
{
services
.AddSingleton<IConnectionFactory>(sp =>
new ConnectionFactory
{
Uri = new Uri("amqps://user:pass@host/vhost"),
AutomaticRecoveryEnabled = true
})
.AddHealthChecks()
.AddRabbitMQ();
}
No packages depend on AspNetCore.HealthChecks.Rabbitmq.
.NET Standard 2.0
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.0)
- RabbitMQ.Client (>= 6.7.0)
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 0 | 12/19/2024 |
8.0.2 | 3 | 11/11/2024 |
8.0.1 | 13 | 05/04/2024 |
8.0.0 | 9 | 05/29/2024 |
7.0.0 | 8 | 05/29/2024 |
7.0.0-rc2.7 | 8 | 03/21/2023 |
7.0.0-rc2.6 | 6 | 05/29/2024 |
7.0.0-rc2.5 | 8 | 05/29/2024 |
7.0.0-rc2.4 | 9 | 05/29/2024 |
6.0.2 | 7 | 05/29/2024 |
6.0.1 | 7 | 05/29/2024 |
6.0.1-rc2.3 | 9 | 05/29/2024 |
6.0.1-rc1.1 | 8 | 05/29/2024 |
6.0.0 | 9 | 05/29/2024 |
5.0.2 | 7 | 05/29/2024 |
5.0.1 | 10 | 05/29/2024 |
5.0.0 | 10 | 09/29/2022 |
5.0.0-preview1 | 6 | 05/29/2024 |
3.1.4 | 10 | 05/29/2024 |
3.1.3 | 13 | 05/29/2024 |
3.1.2 | 2 | 12/09/2024 |
3.1.1 | 9 | 05/29/2024 |
3.1.0 | 9 | 05/29/2024 |
3.0.7 | 6 | 05/29/2024 |
3.0.6 | 10 | 05/29/2024 |
3.0.5 | 9 | 05/29/2024 |
3.0.4 | 5 | 05/29/2024 |
3.0.3 | 7 | 11/12/2024 |
3.0.2 | 10 | 05/29/2024 |
3.0.1 | 11 | 05/29/2024 |
3.0.0 | 10 | 03/21/2023 |
2.2.1 | 8 | 05/29/2024 |
2.2.0 | 9 | 05/29/2024 |