-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
376 additions
and
1 deletion.
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
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
81 changes: 81 additions & 0 deletions
81
src/HealthChecks.IbmMQ/DependencyInjection/IbmMQHealthCheckBuilderExtensions.cs
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,81 @@ | ||
using HealthChecks.IbmMQ; | ||
using IBM.WMQ; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class IbmMQHealthCheckBuilderExtensions | ||
{ | ||
const string NAME = "ibmmq"; | ||
|
||
/// <summary> | ||
/// Add a health check for IbmMQ services using connection properties. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> | ||
/// <param name="queueManager">The name of the queue manager to use.</param> | ||
/// <param name="connectionProperties">The list of properties that will be used for connection.</param> | ||
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'ibmmq' will be used for the name.</param> | ||
/// <param name="failureStatus"> | ||
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then | ||
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. | ||
/// </param> | ||
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> | ||
/// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> | ||
/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> | ||
public static IHealthChecksBuilder AddIbmMQ(this IHealthChecksBuilder builder, string queueManager, Hashtable connectionProperties, string name = default, HealthStatus? failureStatus = default, IEnumerable<string> tags = default, TimeSpan? timeout = default) | ||
{ | ||
return builder.Add(new HealthCheckRegistration( | ||
name ?? NAME, | ||
new IbmMQHealthCheck(queueManager, connectionProperties), | ||
failureStatus, | ||
tags, | ||
timeout)); | ||
} | ||
|
||
/// <summary> | ||
/// Add a health check for IbmMQ services using a managed connection. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> | ||
/// <param name="queueManager">The name of the queue manager to use.</param> | ||
/// <param name="channel">The name of the channel.</param> | ||
/// <param name="connectionInfo">The connection information in the following format HOSTNAME(PORT).</param> | ||
/// <param name="userName">The user name. Optional.</param> | ||
/// <param name="password">The password. Optional</param> | ||
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'ibmmq' will be used for the name.</param> | ||
/// <param name="failureStatus"> | ||
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then | ||
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. | ||
/// </param> | ||
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> | ||
/// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> | ||
/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> | ||
public static IHealthChecksBuilder AddIbmMQManagedConnection(this IHealthChecksBuilder builder, string queueManager, string channel, string connectionInfo, string userName = null, string password = null, string name = default, HealthStatus? failureStatus = default, IEnumerable<string> tags = default, TimeSpan? timeout = default) | ||
{ | ||
return builder.Add(new HealthCheckRegistration( | ||
name ?? NAME, | ||
new IbmMQHealthCheck(queueManager, BuildProperties(channel, connectionInfo, userName, password)), | ||
failureStatus, | ||
tags, | ||
timeout)); | ||
} | ||
private static Hashtable BuildProperties(string channel, string connectionInfo, string userName = null, string password = null) | ||
{ | ||
Hashtable properties = new Hashtable { | ||
{MQC.CHANNEL_PROPERTY, channel}, | ||
{MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED}, | ||
{MQC.CONNECTION_NAME_PROPERTY, connectionInfo} | ||
}; | ||
|
||
if (!string.IsNullOrEmpty(userName)) | ||
properties.Add(MQC.USER_ID_PROPERTY, userName); | ||
if (!string.IsNullOrEmpty(password)) | ||
properties.Add(MQC.PASSWORD_PROPERTY, password); | ||
|
||
return properties; | ||
} | ||
} | ||
} |
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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(NetStandardTargetVersion)</TargetFramework> | ||
<PackageLicenseUrl>$(PackageLicenseUrl)</PackageLicenseUrl> | ||
<PackageProjectUrl>$(PackageProjectUrl)</PackageProjectUrl> | ||
<PackageTags>HealthCheck;IbmMQ</PackageTags> | ||
<Description>HealthChecks.IbmMQ is the health check package for IbmMQ.</Description> | ||
<Version>$(HealthCheckIbmMQ)</Version> | ||
<RepositoryUrl>$(RepositoryUrl)</RepositoryUrl> | ||
<Company>$(Company)</Company> | ||
<Authors>$(Authors)</Authors> | ||
<LangVersion>latest</LangVersion> | ||
<PackageId>AspNetCore.HealthChecks.IbmMQ</PackageId> | ||
<PublishRepositoryUrl>$(PublishRepositoryUrl)</PublishRepositoryUrl> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder)</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="IBMMQDotnetClient" Version="9.1.4" /> | ||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="$(MicrosoftExtensionsDiagnosticsHealthChecks)" /> | ||
</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,38 @@ | ||
using IBM.WMQ; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using System; | ||
using System.Collections; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace HealthChecks.IbmMQ | ||
{ | ||
public class IbmMQHealthCheck : IHealthCheck | ||
{ | ||
private readonly Hashtable _connectionProperties; | ||
private readonly string _queueManager; | ||
|
||
public IbmMQHealthCheck(string queueManager, Hashtable connectionProperties) | ||
{ | ||
_queueManager = queueManager; | ||
_connectionProperties = connectionProperties; | ||
} | ||
|
||
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
using (var connection = new MQQueueManager(_queueManager, _connectionProperties)) | ||
{ | ||
return Task.FromResult( | ||
HealthCheckResult.Healthy()); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromResult( | ||
new HealthCheckResult(context.Registration.FailureStatus, exception: ex)); | ||
} | ||
} | ||
} | ||
} |
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,41 @@ | ||
# IbmMQ Health Check | ||
|
||
This health check verifies the ability to communicate with a IbmMQ 9.0.+ 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 is `ibmmq`. | ||
- `failureStatus`: The `HealthStatus` that should be reported when the health check fails. Default is `HealthStatus.Unhealthy`. | ||
- `tags`: A list of tags that can be used to filter sets of health checks. | ||
- `timeout`: A `System.TimeSpan` representing the timeout of the check. | ||
|
||
### Basic | ||
|
||
Use the extension method where you provide the queue manager name and the connection properties. | ||
|
||
```cs | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
Hashtable connectionProperties = new Hashtable { | ||
{MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_BINDINGS}, | ||
}; | ||
services | ||
.AddHealthChecks() | ||
.AddIbmMQ("QM.TEST.01", connectionProperties); | ||
} | ||
``` | ||
|
||
### Using Managed Client Connection | ||
|
||
For `MQC.TRANSPORT_MQSERIES_MANAGED` connection you can use the following conveniece extension method where you need to specified the channel and the host(port) information. User and password are optional parameters. | ||
|
||
```cs | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services | ||
.AddHealthChecks() | ||
.AddIbmMQManagedConnection("QM.TEST.01", "DEV.APP.SVRCONN", "localhost(1417)", userName: "app", password: "xxx"); | ||
} | ||
``` |
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
Oops, something went wrong.