From 5ade121300ca488e41062f2f1fa113500078c89d Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Thu, 20 Jul 2017 11:55:53 +0200 Subject: [PATCH 1/2] SqlClient version 4.3.1 See: https://github.com/dotnet/corefx/issues/13422 --- src/Greentube.Monitoring.SqlDb/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Greentube.Monitoring.SqlDb/project.json b/src/Greentube.Monitoring.SqlDb/project.json index e8be988..f20f90e 100644 --- a/src/Greentube.Monitoring.SqlDb/project.json +++ b/src/Greentube.Monitoring.SqlDb/project.json @@ -9,7 +9,7 @@ "dependencies": { "Greentube.Monitoring": "1.0.0-*", "NETStandard.Library": "1.6.0", - "System.Data.SqlClient": "4.3.0" + "System.Data.SqlClient": "4.3.1" }, "frameworks": { From b3ec6a44b077ca3cc1c1546ba7e8fed42a5cb953 Mon Sep 17 00:00:00 2001 From: Pawel Mezykowski Date: Thu, 10 Aug 2017 10:27:02 +0200 Subject: [PATCH 2/2] Apache.NMS.ActiveMQ updated to 1.7.2. Bugfix in 1.7.2 exposed problem we had - producing message to the queue without permissions didn't throw, therefore queue name now is configurable --- .../ActiveMqMonitoringConfig.cs | 10 +++++++++- .../ActiveMqMonitoringOptionsExtensions.cs | 8 +++++--- .../ActiveMqPingHealthCheckStrategy.cs | 6 ++++-- .../ActiveMqPingMonitor.cs | 4 +++- .../project.json | 4 ++-- .../ActiveMqPingHealthCheckStrategyTests.cs | 5 +++-- .../ActiveMqPingMonitorTest.cs | 2 ++ 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringConfig.cs b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringConfig.cs index 65a0938..570c024 100644 --- a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringConfig.cs +++ b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringConfig.cs @@ -12,6 +12,10 @@ public interface IActiveMqMonitoringConfig /// Uri Uri { get; } /// + /// holds ActiveMQ queue name where user should have write rights + /// + string QueueName { get; } + /// /// holdes username used to establish ActiveMQ connection /// string User { get; } @@ -28,17 +32,21 @@ public class ActiveMqMonitoringConfig : IActiveMqMonitoringConfig /// Constructor of ActiveMq Monitoring Config /// /// valid ActiveMQ Uri + /// holds ActiveMQ queue name where user should have write rights /// username used to open connection /// password used to open connection - public ActiveMqMonitoringConfig(Uri uri, string user, string password) + public ActiveMqMonitoringConfig(Uri uri, string queueName, string user, string password) { Uri = uri; + QueueName = queueName; User = user; Password = password; } /// public Uri Uri { get; } + /// + public string QueueName { get; } /// public string User { get; } /// diff --git a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringOptionsExtensions.cs b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringOptionsExtensions.cs index c47a6ed..0141334 100644 --- a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringOptionsExtensions.cs +++ b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqMonitoringOptionsExtensions.cs @@ -29,6 +29,7 @@ public static void AddActiveMqMonitor(this MonitoringOptions options, var config = configFactory(configuration, provider); if (config.Uri == null) throw new ArgumentNullException(nameof(config.Uri)); + if (config.QueueName == null) throw new ArgumentNullException(nameof(config.QueueName)); var connectionFactory = new ConnectionFactory() { @@ -36,7 +37,7 @@ public static void AddActiveMqMonitor(this MonitoringOptions options, UserName = config.User, Password = config.Password }; - return new ActiveMqPingMonitor(resourceName, connectionFactory, configuration, provider.GetRequiredService>(), isCritical); + return new ActiveMqPingMonitor(resourceName, connectionFactory, config.QueueName, configuration, provider.GetRequiredService>(), isCritical); }); } @@ -45,13 +46,14 @@ public static void AddActiveMqMonitor(this MonitoringOptions options, /// /// The options. /// Url used to connect to ActiveMQ + /// Queue name where to put ping messages /// User used to connect to ActiveMQ /// Password used to connect to ActiveMQ /// Name of the resource. /// if set to true [is critical]. /// public static void AddActiveMqMonitor(this MonitoringOptions options, - string url, string username, string password, + string url, string queueName, string username, string password, string resourceName = null, bool isCritical = false) { @@ -63,7 +65,7 @@ public static void AddActiveMqMonitor(this MonitoringOptions options, BrokerUri = new Uri(url), UserName = username, Password = password - }, configuration, provider.GetRequiredService>(), isCritical)); + }, queueName, configuration, provider.GetRequiredService>(), isCritical)); } } } diff --git a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingHealthCheckStrategy.cs b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingHealthCheckStrategy.cs index 6877a86..d662058 100644 --- a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingHealthCheckStrategy.cs +++ b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingHealthCheckStrategy.cs @@ -12,17 +12,19 @@ namespace Greentube.Monitoring.Apache.NMS.ActiveMq /// public class ActiveMqPingHealthCheckStrategy : IHealthCheckStrategy { - private readonly string destinationName = "healthCheckPingQueue"; + private readonly string destinationName; private readonly IConnectionFactory connectionFactory; /// /// Initializes a new instance of the class. /// /// Connection factory object - public ActiveMqPingHealthCheckStrategy(IConnectionFactory connectionFactory) + /// DestinationQueueName + public ActiveMqPingHealthCheckStrategy(IConnectionFactory connectionFactory, string destinationName) { if (connectionFactory == null) throw new ArgumentNullException(nameof(connectionFactory)); this.connectionFactory = connectionFactory; + this.destinationName = destinationName; } diff --git a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingMonitor.cs b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingMonitor.cs index e736957..3af1cd9 100644 --- a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingMonitor.cs +++ b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/ActiveMqPingMonitor.cs @@ -14,17 +14,19 @@ public class ActiveMqPingMonitor : ResourceMonitor /// Name of monitored resource /// Factory of ActiveMq specific type of connection /// The logger. + /// Name of queue to connect on ping /// The configuration. /// if set to true [is critical Resource]. public ActiveMqPingMonitor( string resourceName, IConnectionFactory connectionFactory, + string queueName, IResourceMonitorConfiguration configuration, ILogger logger, bool isCritical = false) : base( resourceName ?? "ActiveMQ", - new ActiveMqPingHealthCheckStrategy(connectionFactory), + new ActiveMqPingHealthCheckStrategy(connectionFactory, queueName), configuration, logger, isCritical) diff --git a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/project.json b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/project.json index 0f1a859..fa67821 100644 --- a/src/Greentube.Monitoring.Apache.NMS.ActiveMq/project.json +++ b/src/Greentube.Monitoring.Apache.NMS.ActiveMq/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", //#replaceble "buildOptions": { @@ -8,7 +8,7 @@ "dependencies": { "NETStandard.Library": "1.3.0", - "Apache.NMS.ActiveMQ": "1.7.1", + "Apache.NMS.ActiveMQ": "1.7.2", "Greentube.Monitoring": "1.0.0", "Microsoft.Extensions.DependencyInjection.Abstractions": "1.1.0" }, diff --git a/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingHealthCheckStrategyTests.cs b/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingHealthCheckStrategyTests.cs index 5f557d2..75b3377 100644 --- a/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingHealthCheckStrategyTests.cs +++ b/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingHealthCheckStrategyTests.cs @@ -14,10 +14,11 @@ public class ActiveMqPingHealthCheckStrategyTests private class Fixture { public IConnectionFactory ConnectionFactory { get; set; } = Substitute.For(); + public string DestinationQueueName { get; set; } = "pingQueue"; public ActiveMqPingHealthCheckStrategy GetSut() { - return new ActiveMqPingHealthCheckStrategy(ConnectionFactory); + return new ActiveMqPingHealthCheckStrategy(ConnectionFactory, DestinationQueueName); } } @@ -83,7 +84,7 @@ public async Task Check_SendMessage_ReturnsTrue() _fixture.ConnectionFactory.CreateConnection().Returns(connection); connection.CreateSession().Returns(session); - session.CreateProducer(Arg.Any()).Returns(producer); + session.CreateProducer(Arg.Is(destination => destination.QueueName == _fixture.DestinationQueueName)).Returns(producer); var target = _fixture.GetSut(); var result = await target.Check(CancellationToken.None); diff --git a/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingMonitorTest.cs b/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingMonitorTest.cs index 8fc5069..928164f 100644 --- a/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingMonitorTest.cs +++ b/test/Greentube.Monitoring.Apache.NMS.ActiveMq.Tests/ActiveMqPingMonitorTest.cs @@ -20,12 +20,14 @@ private sealed class Fixture private bool IsCritical { get; } = true; public string ResourceName { private get; set; } = "ActiveMQ 123"; + public string DestinationQueueName { private get; set; } = "pingQueue"; public ActiveMqPingMonitor GetSut() { return new ActiveMqPingMonitor( ResourceName, ConnectionFactory, + DestinationQueueName, ResourceMonitorConfiguration, Logger, IsCritical);