-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for RabbitMQ.Client version 7. (#2323)
* Add support for RabbitMQ.Client version 7. RabbitMQ.Client version 7 made major breaking changes - interface renames, all sync methods are removed and only async methods remain. Handle this breaking change by splitting our package into 2, one for each major version. 1. For the current HealthChecks.Rabbitmq package, update to the new 7.0.0 version and update so the health checks will work with v7. 2. We add a new, forked component named HealthChecks.Rabbitmq.v6 which will have a dependency on 6.x . People who want to keep using the version 6 can opt into using this package. We put a NuGet version limit on our dependency: [6.8.1,7.0.0). This way people won't be able to update to the 7.0.0 version, which will break their app. They will need to migrate back to the base package to use version 7. 3. When RabbitMQ.Client v6 is no longer supported, we can dead-end the `HealthChecks.Rabbitmq.v6` package. Fix #2319 - add workflows for the new v6 package * Fix path
- Loading branch information
Showing
13 changed files
with
283 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: HealthChecks RabbitMQ v6 CD | ||
|
||
on: | ||
push: | ||
tags: | ||
- release-rabbitmq-* | ||
- release-all-* | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/reusable_cd_workflow.yml | ||
secrets: inherit | ||
with: | ||
BUILD_CONFIG: Release | ||
PROJECT_PATH: ./src/HealthChecks.Rabbitmq.v6/HealthChecks.Rabbitmq.v6.csproj | ||
PACKAGE_NAME: AspNetCore.HealthChecks.Rabbitmq.v6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: HealthChecks RabbitMQ v6 Preview CD | ||
|
||
on: | ||
push: | ||
tags: | ||
- preview-rabbitmq-* | ||
- preview-all-* | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/reusable_cd_preview_workflow.yml | ||
secrets: inherit | ||
with: | ||
BUILD_CONFIG: Release | ||
VERSION_SUFFIX_PREFIX: rc1 | ||
PROJECT_PATH: ./src/HealthChecks.Rabbitmq.v6/HealthChecks.Rabbitmq.v6.csproj | ||
PACKAGE_NAME: AspNetCore.HealthChecks.Rabbitmq.v6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/HealthChecks.Rabbitmq.v6/HealthChecks.Rabbitmq.v6.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>$(DefaultLibraryTargetFrameworks)</TargetFrameworks> | ||
<PackageTags>$(PackageTags);RabbitMQ</PackageTags> | ||
<Description>HealthChecks.RabbitMQ is the health check package for RabbitMQ.Client (version 6).</Description> | ||
<VersionPrefix>$(HealthCheckRabbitMQ)</VersionPrefix> | ||
<AssemblyName>HealthChecks.Rabbitmq</AssemblyName> | ||
<RootNamespace>HealthChecks.RabbitMQ</RootNamespace> <!--For backward naming compatibility--> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="RabbitMQ.Client" VersionOverride="[6.8.1,7.0.0)" /> | ||
|
||
<Compile Include="../HealthCheckResultTask.cs" /> | ||
<Compile Include="../HealthChecks.Rabbitmq/DependencyInjection/RabbitMQHealthCheckBuilderExtensions.cs" Link="DependencyInjection/RabbitMQHealthCheckBuilderExtensions.cs" /> | ||
<Compile Include="../HealthChecks.Rabbitmq/RabbitMQHealthCheckOptions.cs" /> | ||
|
||
<None Include="../HealthChecks.Rabbitmq/README.md" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Collections.Concurrent; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using RabbitMQ.Client; | ||
|
||
namespace HealthChecks.RabbitMQ; | ||
|
||
/// <summary> | ||
/// A health check for RabbitMQ services. | ||
/// </summary> | ||
public class RabbitMQHealthCheck : IHealthCheck | ||
{ | ||
private static readonly ConcurrentDictionary<RabbitMQHealthCheckOptions, IConnection> _connections = new(); | ||
|
||
private IConnection? _connection; | ||
private readonly RabbitMQHealthCheckOptions _options; | ||
|
||
public RabbitMQHealthCheck(RabbitMQHealthCheckOptions options) | ||
{ | ||
_options = Guard.ThrowIfNull(options); | ||
_connection = options.Connection; | ||
|
||
if (_connection is null && _options.ConnectionFactory is null && _options.ConnectionUri is null) | ||
{ | ||
throw new ArgumentException("A connection, connection factory, or connection string must be set!", nameof(options)); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
// TODO: cancellationToken unused, see https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/714 | ||
try | ||
{ | ||
using var model = EnsureConnection().CreateModel(); | ||
return HealthCheckResultTask.Healthy; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromResult(new HealthCheckResult(context.Registration.FailureStatus, exception: ex)); | ||
} | ||
} | ||
|
||
private IConnection EnsureConnection() | ||
{ | ||
_connection ??= _connections.GetOrAdd(_options, _ => | ||
{ | ||
var factory = _options.ConnectionFactory; | ||
|
||
if (factory is null) | ||
{ | ||
Guard.ThrowIfNull(_options.ConnectionUri); | ||
factory = new ConnectionFactory | ||
{ | ||
Uri = _options.ConnectionUri, | ||
AutomaticRecoveryEnabled = true | ||
}; | ||
|
||
if (_options.RequestedConnectionTimeout is not null) | ||
{ | ||
((ConnectionFactory)factory).RequestedConnectionTimeout = _options.RequestedConnectionTimeout.Value; | ||
} | ||
|
||
if (_options.Ssl is not null) | ||
{ | ||
((ConnectionFactory)factory).Ssl = _options.Ssl; | ||
} | ||
} | ||
|
||
return factory.CreateConnection(); | ||
}); | ||
|
||
return _connection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/HealthChecks.RabbitMQ.Tests/HealthChecks.RabbitMQ.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/HealthChecks.RabbitMQ.v6.Tests/HealthChecks.RabbitMQ.v6.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>HealthChecks.RabbitMQ.Tests</AssemblyName> | ||
<DefineConstants>$(DefineConstants);RABBITMQ_V6</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\HealthChecks.Rabbitmq.v6\HealthChecks.Rabbitmq.v6.csproj" /> | ||
|
||
<Compile Include="../HealthChecks.RabbitMQ.Tests/DependencyInjection/RegistrationTests.cs" Link="DependencyInjection/RegistrationTests.cs" /> | ||
<Compile Include="../HealthChecks.RabbitMQ.Tests/Functional/RabbitHealthCheckTests.cs" Link="Functional/RabbitHealthCheckTests.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.