Skip to content

Commit 964a8f7

Browse files
samtriondependabot[bot]github-actions[bot]github-actions
authored
feat: Apache ActiveMQ package (#566)
* chore(deps): bump Verify.Xunit from 28.6.0 to 28.6.1 in the verify group (#575) * chore(deps): bump StackExchange.Redis from 2.8.22 to 2.8.24 (#576) * chore(ci): bump dailydevops/pipelines from 0.12.47 to 0.14.1 (#577) * chore(deps): bump NetEvolve.Defaults from 1.3.25 to 1.3.28 (#578) * chore(deps): bump Verify.Xunit from 28.6.1 to 28.7.0 in the verify group (#579) * chore(deps): bump Oracle.ManagedDataAccess.Core from 23.6.1 to 23.7.0 (#580) * chore(ci): bump peter-evans/create-pull-request from 7.0.5 to 7.0.6 (#581) * chore(deps): bump CSharpier.MSBuild from 0.30.3 to 0.30.4 (#582) * chore(deps): bump the coverlet group with 2 updates (#583) * chore: Updated LICENSE [skip ci] (#584) Co-authored-by: github-actions <github-actions@github.com> * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(ci): bump dailydevops/pipelines from 0.14.1 to 0.14.10 (#585) * chore(deps): bump NetEvolve.Defaults from 1.3.28 to 1.3.32 (#586) * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump NetEvolve.Defaults from 1.3.32 to 1.3.36 (#587) * chore(deps): bump Verify.Xunit from 28.7.0 to 28.8.1 in the verify group (#588) * chore(deps): bump CSharpier.MSBuild from 0.30.4 to 0.30.5 (#589) * chore(deps): bump NetEvolve.Defaults from 1.3.36 to 1.3.39 (#590) * chore(deps): bump Confluent.Kafka from 2.6.1 to 2.8.0 (#591) * chore(ci): bump dailydevops/pipelines from 0.14.10 to 0.14.13 (#592) * chore(deps): bump the xunit group with 2 updates (#593) * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump SonarAnalyzer.CSharp (#594) * chore(deps): bump CSharpier.MSBuild from 0.30.5 to 0.30.6 (#595) * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump Verify.Xunit from 28.8.1 to 28.9.0 in the verify group (#596) * chore(deps): bump System.Text.Json from 9.0.0 to 9.0.1 (#598) * chore(deps): bump Microsoft.Data.Sqlite from 9.0.0 to 9.0.1 (#599) * chore(deps): bump Azure.Data.Tables from 12.9.1 to 12.10.0 (#597) * chore(deps): bump Azure.Identity from 1.13.1 to 1.13.2 (#600) * chore(deps): bump the coverlet group with 2 updates (#601) * chore(deps): bump ClickHouse.Client from 7.9.1 to 7.10.0 (#602) * chore(deps): bump MySql.Data and System.Text.Json (#603) * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump NetEvolve.Defaults from 1.3.39 to 1.3.47 (#604) * chore(deps): bump PublicApiGenerator from 11.3.0 to 11.4.0 (#605) * chore(deps): bump TngTech.ArchUnitNET.xUnit from 0.11.1 to 0.11.2 (#606) * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump Roslynator.Analyzers from 4.12.10 to 4.12.11 (#609) * chore(deps): bump PublicApiGenerator from 11.4.0 to 11.4.1 (#607) Bumps [PublicApiGenerator](https://github.com/PublicApiGenerator/PublicApiGenerator) from 11.4.0 to 11.4.1. - [Release notes](https://github.com/PublicApiGenerator/PublicApiGenerator/releases) - [Commits](PublicApiGenerator/PublicApiGenerator@11.4.0...11.4.1) --- updated-dependencies: - dependency-name: PublicApiGenerator dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump NetEvolve.Defaults from 1.3.47 to 1.3.48 (#608) Bumps [NetEvolve.Defaults](https://github.com/dailydevops/defaults) from 1.3.47 to 1.3.48. - [Release notes](https://github.com/dailydevops/defaults/releases) - [Commits](dailydevops/defaults@1.3.47...1.3.48) --- updated-dependencies: - dependency-name: NetEvolve.Defaults dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump SonarAnalyzer.CSharp (#610) Bumps [SonarAnalyzer.CSharp](https://github.com/SonarSource/sonar-dotnet) from 10.5.0.109200 to 10.6.0.109712. - [Release notes](https://github.com/SonarSource/sonar-dotnet/releases) - [Commits](SonarSource/sonar-dotnet@10.5.0.109200...10.6.0.109712) --- updated-dependencies: - dependency-name: SonarAnalyzer.CSharp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(ci): bump dailydevops/pipelines from 0.14.13 to 0.14.33 (#612) * chore(deps): bump NetEvolve.Extensions.XUnit from 2.5.0 to 2.5.63 (#613) * chore(deps): bump NetEvolve.Arguments from 1.3.0 to 1.3.37 (#614) * chore(deps): bump NetEvolve.Arguments from 1.3.37 to 1.3.43 (#616) * chore(deps): bump NetEvolve.Extensions.XUnit from 2.5.63 to 2.5.67 (#617) * chore(deps): bump Verify.Xunit in the verify group (#618) * chore(deps): bump Roslynator.Analyzers from 4.12.11 to 4.13.0 (#619) * chore(deps): bump the testcontainers group with 9 updates (#620) * chore(deps): bump System.Text.Json from 9.0.1 to 9.0.2 (#621) * chore(deps): bump System.Text.Json from 9.0.1 to 9.0.2 Bumps [System.Text.Json](https://github.com/dotnet/runtime) from 9.0.1 to 9.0.2. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v9.0.1...v9.0.2) --- updated-dependencies: - dependency-name: System.Text.Json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * fix: Upgraded `NetEvolve.Defaults` * fix: Upgraded `Microsoft.AspNetCore.TestHost` manually * fix: Upgraded `NetEvolve.Defaults` to `1.3.61` --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Martin Stühmer <me@samtrion.net> * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(ci): bump dailydevops/pipelines from 0.14.33 to 0.14.41 (#624) * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump Microsoft.VisualStudio.Threading.Analyzers (#622) * chore(deps): bump Verify.Xunit in the verify group (#623) * chore(deps): bump xunit.runner.visualstudio in the xunit group (#625) * chore(deps): bump Microsoft.Data.Sqlite from 9.0.1 to 9.0.2 (#626) * chore(deps): bump PublicApiGenerator from 11.4.1 to 11.4.2 (#627) * chore(ci): bump peter-evans/create-pull-request from 7.0.6 to 7.0.7 (#628) * chore(deps): bump Verify.Xunit in the verify group (#629) * chore(deps): bump the testcontainers group with 9 updates (#631) * chore(deps): bump Verify.Xunit in the verify group (#632) * chore(deps): bump Verify.Xunit in the verify group (#634) * chore(deps): bump PublicApiGenerator from 11.4.2 to 11.4.5 (#635) * chore(ci): bump peter-evans/create-pull-request from 7.0.7 to 7.0.8 (#636) * chore(deps): bump NetEvolve.Defaults from 1.3.61 to 1.3.66 (#637) * chore(deps): bump Roslynator.Analyzers from 4.13.0 to 4.13.1 (#630) * chore(deps): bump ClickHouse.Client from 7.10.0 to 7.13.0 (#638) * chore(deps): bump Verify.Xunit in the verify group (#639) * chore(deps): bump NetEvolve.Defaults from 1.3.66 to 1.3.69 (#640) * chore(deps): bump System.Text.Json from 9.0.2 to 9.0.3 (#642) * chore(deps): bump Microsoft.Data.Sqlite from 9.0.2 to 9.0.3 (#643) * chore(deps): bump Verify.Xunit in the verify group (#641) * chore(deps): bump Verify.Xunit in the verify group (#644) * chore(deps): bump Microsoft.VisualStudio.Threading.Analyzers (#645) * chore(deps): bump Confluent.Kafka from 2.8.0 to 2.9.0 (#649) * chore(deps): bump ClickHouse.Client from 7.13.0 to 7.13.1 (#646) * chore(deps): bump NetEvolve.Defaults from 1.3.69 to 1.3.70 (#648) * chore(deps): bump Npgsql from 9.0.2 to 9.0.3 (#633) * chore(deps): bump Verify.Xunit in the verify group (#647) * chore(deps): bump GitVersion.MsBuild from 6.1.0 to 6.2.0 (#650) * chore(deps): bump Verify.Xunit from 29.1.0 to 29.2.0 in the verify group (#651) * chore(deps): bump NetEvolve.Extensions.XUnit from 2.5.67 to 2.5.105 (#652) * chore(ci): bump dailydevops/pipelines from 0.14.41 to 0.14.68 (#653) * chore(deps): bump NetEvolve.Defaults from 1.3.70 to 1.3.71 (#654) * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump System.Text.Json from 9.0.3 to 9.0.4 (#655) * chore(deps): bump Microsoft.Data.Sqlite from 9.0.3 to 9.0.4 (#656) * chore(deps): bump NetEvolve.Defaults from 1.3.71 to 1.3.74 (#657) * chore(deps): bump NetEvolve.Arguments from 1.3.43 to 1.3.68 (#658) * chore(deps): bump the testcontainers group with 9 updates (#659) * chore(deps): bump Confluent.Kafka from 2.9.0 to 2.10.0 (#660) * chore(ci): bump dailydevops/pipelines from 0.14.68 to 0.14.79 (#677) * chore(deps): bump Oracle.ManagedDataAccess.Core from 23.7.0 to 23.8.0 (#675) * chore(deps): bump PublicApiGenerator from 11.4.5 to 11.4.6 (#664) * chore(deps): bump Microsoft.NET.Test.Sdk from 17.12.0 to 17.13.0 (#667) * chore(deps): bump Azure.Storage.Queues from 12.21.0 to 12.22.0 (#669) * chore(deps): bump Dapr.Client from 1.14.0 to 1.15.4 (#671) * chore(deps): bump Verify.Xunit from 29.2.0 to 29.3.0 in the verify group (#662) * chore(deps): bump GitVersion.MsBuild from 6.2.0 to 6.3.0 (#665) * chore(deps): bump TngTech.ArchUnitNET.xUnit from 0.11.2 to 0.11.4 (#676) * chore(deps): bump Azure.Storage.Blobs from 12.23.0 to 12.24.0 (#673) * chore(deps): bump StackExchange.Redis from 2.8.24 to 2.8.31 (#674) * chore(deps): bump ClickHouse.Client from 7.13.1 to 7.13.2 (#661) * chore(deps): bump MySql.Data and System.Text.Json (#668) * chore(deps): bump Microsoft.AspNetCore.TestHost from 8.0.13 to 8.0.15 (#670) Bumps [Microsoft.AspNetCore.TestHost](https://github.com/dotnet/aspnetcore) from 8.0.13 to 8.0.15. - [Release notes](https://github.com/dotnet/aspnetcore/releases) - [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md) - [Commits](dotnet/aspnetcore@v8.0.13...v8.0.15) --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.TestHost dependency-version: 8.0.15 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(template): sync with dailydevops/dotnet-template [skip ci] * chore(deps): bump NetEvolve.Defaults from 1.3.74 to 1.3.79 (#679) * chore(deps): bump NetEvolve.Arguments from 1.3.68 to 1.3.77 (#680) * chore(deps): bump Verify.Xunit from 29.5.0 to 30.0.0 in the verify group (#678) * feat: Apache ActiveMQ package * chore: remove duplicated code * fix: Missing nullable * chore: Added further tests * fix(style): Reformatted based on rules of Csharpier 1.0.1 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent 7754fe1 commit 964a8f7

22 files changed

+616
-2
lines changed

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/>
2323
</ItemGroup>
2424
<ItemGroup>
25+
<PackageVersion Include="Apache.NMS.ActiveMQ" Version="2.1.0" />
2526
<PackageVersion Include="Azure.Data.Tables" Version="12.10.0" />
2627
<PackageVersion Include="Azure.Identity" Version="1.13.2" />
2728
<PackageVersion Include="Azure.Storage.Blobs" Version="12.24.0" />
@@ -48,6 +49,7 @@
4849
<PackageVersion Include="StackExchange.Redis" Version="2.8.31" />
4950
<PackageVersion Include="System.Data.SqlClient" Version="4.9.0" />
5051
<PackageVersion Include="System.Text.Json" Version="9.0.4" />
52+
<PackageVersion Include="Testcontainers.ActiveMq" Version="4.1.0" />
5153
<PackageVersion Include="Testcontainers.Azurite" Version="4.4.0" />
5254
<PackageVersion Include="Testcontainers.ClickHouse" Version="4.4.0" />
5355
<PackageVersion Include="Testcontainers.Kafka" Version="4.4.0" />

HealthChecks.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetEvolve.HealthChecks.Test
6565
EndProject
6666
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetEvolve.HealthChecks.Tests.Architecture", "tests\NetEvolve.HealthChecks.Tests.Architecture\NetEvolve.HealthChecks.Tests.Architecture.csproj", "{17BCA132-1FBB-46C1-B6A1-60F64969383D}"
6767
EndProject
68+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetEvolve.HealthChecks.Apache.ActiveMq", "src\NetEvolve.HealthChecks.Apache.ActiveMq\NetEvolve.HealthChecks.Apache.ActiveMq.csproj", "{1F26E911-E73F-409A-87FC-1214EF36FF61}"
69+
EndProject
6870
Global
6971
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7072
Debug|Any CPU = Debug|Any CPU
@@ -315,6 +317,18 @@ Global
315317
{17BCA132-1FBB-46C1-B6A1-60F64969383D}.Release|x64.Build.0 = Release|Any CPU
316318
{17BCA132-1FBB-46C1-B6A1-60F64969383D}.Release|x86.ActiveCfg = Release|Any CPU
317319
{17BCA132-1FBB-46C1-B6A1-60F64969383D}.Release|x86.Build.0 = Release|Any CPU
320+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
321+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Debug|Any CPU.Build.0 = Debug|Any CPU
322+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Debug|x64.ActiveCfg = Debug|Any CPU
323+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Debug|x64.Build.0 = Debug|Any CPU
324+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Debug|x86.ActiveCfg = Debug|Any CPU
325+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Debug|x86.Build.0 = Debug|Any CPU
326+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Release|Any CPU.ActiveCfg = Release|Any CPU
327+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Release|Any CPU.Build.0 = Release|Any CPU
328+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Release|x64.ActiveCfg = Release|Any CPU
329+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Release|x64.Build.0 = Release|Any CPU
330+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Release|x86.ActiveCfg = Release|Any CPU
331+
{1F26E911-E73F-409A-87FC-1214EF36FF61}.Release|x86.Build.0 = Release|Any CPU
318332
EndGlobalSection
319333
GlobalSection(SolutionProperties) = preSolution
320334
HideSolutionNode = FALSE
@@ -340,6 +354,7 @@ Global
340354
{66406BE8-0281-4C95-B90B-20CAE4516A16} = {E412EC77-2022-4A1D-AAC1-FDF1A4A45827}
341355
{2B089420-E791-44E7-B471-F6F527B33E1C} = {E412EC77-2022-4A1D-AAC1-FDF1A4A45827}
342356
{17BCA132-1FBB-46C1-B6A1-60F64969383D} = {E412EC77-2022-4A1D-AAC1-FDF1A4A45827}
357+
{1F26E911-E73F-409A-87FC-1214EF36FF61} = {EF615D18-42E2-48A4-8EBA-E652DC574C56}
343358
EndGlobalSection
344359
GlobalSection(ExtensibilityGlobals) = postSolution
345360
SolutionGuid = {28B4CC2B-39E8-49C0-9687-78121BD83A53}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace NetEvolve.HealthChecks.Apache.ActiveMq;
2+
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.Options;
5+
using NetEvolve.Arguments;
6+
using static Microsoft.Extensions.Options.ValidateOptionsResult;
7+
8+
internal sealed class ActiveMqConfigure
9+
: IConfigureNamedOptions<ActiveMqOptions>,
10+
IValidateOptions<ActiveMqOptions>
11+
{
12+
private readonly IConfiguration _configuration;
13+
14+
public ActiveMqConfigure(IConfiguration configuration) => _configuration = configuration;
15+
16+
public void Configure(string? name, ActiveMqOptions options)
17+
{
18+
Argument.ThrowIfNullOrWhiteSpace(name);
19+
_configuration.Bind($"HealthChecks:ActiveMq:{name}", options);
20+
}
21+
22+
public void Configure(ActiveMqOptions options) => Configure(Options.DefaultName, options);
23+
24+
public ValidateOptionsResult Validate(string? name, ActiveMqOptions options)
25+
{
26+
if (string.IsNullOrWhiteSpace(name))
27+
{
28+
return Fail("The name cannot be null or whitespace.");
29+
}
30+
31+
if (options is null)
32+
{
33+
return Fail("The option cannot be null.");
34+
}
35+
36+
if (string.IsNullOrWhiteSpace(options.BrokerAddress))
37+
{
38+
return Fail("The broker address cannot be null or whitespace.");
39+
}
40+
41+
return Success;
42+
}
43+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace NetEvolve.HealthChecks.Apache.ActiveMq;
2+
3+
using System.Collections.Concurrent;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using global::Apache.NMS;
7+
using global::Apache.NMS.ActiveMQ;
8+
using Microsoft.Extensions.Diagnostics.HealthChecks;
9+
using Microsoft.Extensions.Options;
10+
using NetEvolve.Extensions.Tasks;
11+
using NetEvolve.HealthChecks.Abstractions;
12+
13+
internal sealed class ActiveMqHealthCheck : ConfigurableHealthCheckBase<ActiveMqOptions>
14+
{
15+
public ActiveMqHealthCheck(IOptionsMonitor<ActiveMqOptions> optionsMonitor)
16+
: base(optionsMonitor) { }
17+
18+
protected override async ValueTask<HealthCheckResult> ExecuteHealthCheckAsync(
19+
string name,
20+
HealthStatus failureStatus,
21+
ActiveMqOptions options,
22+
CancellationToken cancellationToken
23+
)
24+
{
25+
using var client = await ClientFactory
26+
.GetConnectionAsync(options, cancellationToken)
27+
.ConfigureAwait(false);
28+
29+
var isValid = await client
30+
.StartAsync()
31+
.WithTimeoutAsync(options.Timeout, cancellationToken)
32+
.ConfigureAwait(false);
33+
34+
return HealthCheckState(client.IsStarted && isValid, name);
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace NetEvolve.HealthChecks.Apache.ActiveMq;
2+
3+
public class ActiveMqOptions
4+
{
5+
public string? BrokerAddress { get; set; }
6+
public string? Username
7+
{
8+
get
9+
{
10+
if (string.IsNullOrWhiteSpace(field))
11+
{
12+
return null;
13+
}
14+
15+
return field;
16+
}
17+
set;
18+
}
19+
public string? Password
20+
{
21+
get
22+
{
23+
if (string.IsNullOrWhiteSpace(field))
24+
{
25+
return null;
26+
}
27+
28+
return field;
29+
}
30+
set;
31+
}
32+
33+
/// <summary>
34+
/// Gets or sets the timeout in milliseconds for executing the healthcheck.
35+
/// </summary>
36+
public int Timeout { get; set; } = 100;
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace NetEvolve.HealthChecks.Apache.ActiveMq;
2+
3+
using System.Collections.Concurrent;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using global::Apache.NMS;
7+
using global::Apache.NMS.ActiveMQ;
8+
9+
internal static class ClientFactory
10+
{
11+
private static readonly ConcurrentDictionary<string, ConnectionFactory> _factories = new(
12+
StringComparer.OrdinalIgnoreCase
13+
);
14+
15+
public static async ValueTask<IConnection> GetConnectionAsync(
16+
ActiveMqOptions options,
17+
CancellationToken cancellationToken
18+
)
19+
{
20+
var factory = _factories.GetOrAdd(
21+
options.BrokerAddress,
22+
brokerAddress => new ConnectionFactory(brokerAddress)
23+
);
24+
25+
return options.Username is null && options.Password is null
26+
? await factory.CreateConnectionAsync().ConfigureAwait(false)
27+
: await factory
28+
.CreateConnectionAsync(options.Username, options.Password)
29+
.ConfigureAwait(false);
30+
}
31+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace NetEvolve.HealthChecks.Apache.ActiveMq;
2+
3+
using System;
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Linq;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Diagnostics.HealthChecks;
8+
using NetEvolve.Arguments;
9+
using NetEvolve.HealthChecks.Abstractions;
10+
11+
/// <summary>
12+
/// Extensions methods for <see cref="IHealthChecksBuilder"/> with custom Health Checks.
13+
/// </summary>
14+
public static class DependencyInjectionExtensions
15+
{
16+
private static readonly string[] _defaultTags = ["activemq", "message-queue"];
17+
18+
/// <summary>
19+
/// Add a health check for Apache ActiveMq.
20+
/// </summary>
21+
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
22+
/// <param name="name">The name of the <see cref="ActiveMqHealthCheck"/>.</param>
23+
/// <param name="options">An optional action to configure.</param>
24+
/// <param name="tags">A list of additional tags that can be used to filter sets of health checks. Optional.</param>
25+
/// <exception cref="ArgumentNullException">The <paramref name="builder"/> is <see langword="null" />.</exception>
26+
/// <exception cref="ArgumentNullException">The <paramref name="name"/> is <see langword="null" />.</exception>
27+
/// <exception cref="ArgumentException">The <paramref name="name"/> is <see langword="null" /> or <c>whitespace</c>.</exception>
28+
/// <exception cref="ArgumentException">The <paramref name="name"/> is already in use.</exception>
29+
/// <exception cref="ArgumentNullException">The <paramref name="tags"/> is <see langword="null" />.</exception>
30+
public static IHealthChecksBuilder AddActiveMq(
31+
[NotNull] this IHealthChecksBuilder builder,
32+
[NotNull] string name,
33+
Action<ActiveMqOptions>? options = null,
34+
params string[] tags
35+
)
36+
{
37+
ArgumentNullException.ThrowIfNull(builder);
38+
Argument.ThrowIfNullOrEmpty(name);
39+
ArgumentNullException.ThrowIfNull(tags);
40+
41+
if (!builder.IsServiceTypeRegistered<ActiveMqCheckMarker>())
42+
{
43+
_ = builder
44+
.Services.AddSingleton<ActiveMqCheckMarker>()
45+
.AddSingleton<ActiveMqHealthCheck>()
46+
.ConfigureOptions<ActiveMqConfigure>();
47+
}
48+
49+
if (builder.IsNameAlreadyUsed<ActiveMqHealthCheck>(name))
50+
{
51+
throw new ArgumentException($"Name `{name}` already in use.", nameof(name), null);
52+
}
53+
54+
if (options is not null)
55+
{
56+
_ = builder.Services.Configure(name, options);
57+
}
58+
59+
return builder.AddCheck<ActiveMqHealthCheck>(
60+
name,
61+
HealthStatus.Unhealthy,
62+
_defaultTags.Union(tags, StringComparer.OrdinalIgnoreCase)
63+
);
64+
}
65+
66+
private sealed partial class ActiveMqCheckMarker;
67+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>$(_ProjectTargetFrameworks)</TargetFrameworks>
4+
<Description>Contains HealthChecks for Apache ActiveMq, based on the NuGet package `Apache.NMS.ActiveMQ`.</Description>
5+
<PackageTags>$(PackageTags);apache;activemq;</PackageTags>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="Apache.NMS.ActiveMQ" />
9+
<PackageReference Include="NetEvolve.Extensions.Tasks" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<ProjectReference Include="..\NetEvolve.HealthChecks.Abstractions\NetEvolve.HealthChecks.Abstractions.csproj" />
13+
</ItemGroup>
14+
</Project>

src/NetEvolve.HealthChecks.Apache.Kafka/NetEvolve.HealthChecks.Apache.Kafka.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>$(_ProjectTargetFrameworks)</TargetFrameworks>
44
<Description>Contains HealthChecks for Apache Kafka, based on the NuGet package `Confluent.Kafka`.</Description>
5-
<PackageTags>$(PackageTags);kafka;</PackageTags>
5+
<PackageTags>$(PackageTags);apache;kafka;</PackageTags>
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Confluent.Kafka" />

tests/NetEvolve.HealthChecks.Tests.Architecture/HealthCheckArchitecture.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ private static Architecture LoadArchitecture()
1919
{
2020
System.Reflection.Assembly[] assemblies =
2121
[
22+
// Apache
23+
typeof(Apache.ActiveMq.ActiveMqHealthCheck).Assembly,
2224
typeof(Apache.Kafka.KafkaCheck).Assembly,
25+
// Azure
2326
typeof(Azure.Blobs.BlobContainerAvailableHealthCheck).Assembly,
2427
typeof(Azure.Queues.QueueClientAvailableHealthCheck).Assembly,
2528
typeof(Azure.Tables.TableClientAvailableHealthCheck).Assembly,
29+
// others
2630
typeof(ClickHouse.ClickHouseCheck).Assembly,
2731
typeof(Dapr.DaprHealthCheck).Assembly,
2832
typeof(MySql.MySqlCheck).Assembly,

0 commit comments

Comments
 (0)