-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for RabbitMQ.Client version 7. #2323
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e614f1
Add support for RabbitMQ.Client version 7.
eerhardt 6f1ffaa
Swap around the versions now that we are going to release a 9.0 major…
eerhardt f63dfdf
Limit the nuget version used to less than 7.0.
eerhardt 6fa0f1c
PR feedback
eerhardt 1f5df36
Fix path
eerhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not related to this PR, but it shows that we really need to get rid of that static cache, as it brings so much complexity and increases a risk for various bugs (leaks etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - agreed. I will try to make that change next.