Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitlab2/master' into bugfix-gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-garcia committed Sep 4, 2017
2 parents 9f6ad4d + 88d4666 commit 218c55d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public interface IActiveMqMonitoringConfig
/// </summary>
Uri Uri { get; }
/// <summary>
/// holds ActiveMQ queue name where user should have write rights
/// </summary>
string QueueName { get; }
/// <summary>
/// holdes username used to establish ActiveMQ connection
/// </summary>
string User { get; }
Expand All @@ -28,17 +32,21 @@ public class ActiveMqMonitoringConfig : IActiveMqMonitoringConfig
/// Constructor of ActiveMq Monitoring Config
/// </summary>
/// <param name="uri">valid ActiveMQ Uri</param>
/// <param name="queueName">holds ActiveMQ queue name where user should have write rights</param>
/// <param name="user">username used to open connection</param>
/// <param name="password">password used to open connection</param>
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;
}

/// <inheritdoc cref="IActiveMqMonitoringConfig.Uri"/>
public Uri Uri { get; }
/// <inheritdoc cref="IActiveMqMonitoringConfig.Uri"/>
public string QueueName { get; }
/// <inheritdoc cref="IActiveMqMonitoringConfig.User"/>
public string User { get; }
/// <inheritdoc cref="IActiveMqMonitoringConfig.Password"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ 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()
{
BrokerUri = config.Uri,
UserName = config.User,
Password = config.Password
};
return new ActiveMqPingMonitor(resourceName, connectionFactory, configuration, provider.GetRequiredService<ILogger<ActiveMqPingMonitor>>(), isCritical);
return new ActiveMqPingMonitor(resourceName, connectionFactory, config.QueueName, configuration, provider.GetRequiredService<ILogger<ActiveMqPingMonitor>>(), isCritical);
});
}

Expand All @@ -45,13 +46,14 @@ public static void AddActiveMqMonitor(this MonitoringOptions options,
/// </summary>
/// <param name="options">The options.</param>
/// <param name="url">Url used to connect to ActiveMQ</param>
/// <param name="queueName">Queue name where to put ping messages</param>
/// <param name="username">User used to connect to ActiveMQ</param>
/// <param name="password">Password used to connect to ActiveMQ</param>
/// <param name="resourceName">Name of the resource.</param>
/// <param name="isCritical">if set to <c>true</c> [is critical].</param>
/// <exception cref="ArgumentNullException"></exception>
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)
{
Expand All @@ -63,7 +65,7 @@ public static void AddActiveMqMonitor(this MonitoringOptions options,
BrokerUri = new Uri(url),
UserName = username,
Password = password
}, configuration, provider.GetRequiredService<ILogger<ActiveMqPingMonitor>>(), isCritical));
}, queueName, configuration, provider.GetRequiredService<ILogger<ActiveMqPingMonitor>>(), isCritical));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ namespace Greentube.Monitoring.Apache.NMS.ActiveMq
/// </summary>
public class ActiveMqPingHealthCheckStrategy : IHealthCheckStrategy
{
private readonly string destinationName = "healthCheckPingQueue";
private readonly string destinationName;
private readonly IConnectionFactory connectionFactory;

/// <summary>
/// Initializes a new instance of the <see cref="ActiveMqPingHealthCheckStrategy"/> class.
/// </summary>
/// <param name="connectionFactory">Connection factory object</param>
public ActiveMqPingHealthCheckStrategy(IConnectionFactory connectionFactory)
/// <param name="destinationName">DestinationQueueName</param>
public ActiveMqPingHealthCheckStrategy(IConnectionFactory connectionFactory, string destinationName)
{
if (connectionFactory == null) throw new ArgumentNullException(nameof(connectionFactory));
this.connectionFactory = connectionFactory;
this.destinationName = destinationName;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ public class ActiveMqPingMonitor : ResourceMonitor
/// <param name="resourceName">Name of monitored resource</param>
/// <param name="connectionFactory">Factory of ActiveMq specific type of connection</param>
/// <param name="logger">The logger.</param>
/// <param name="queueName">Name of queue to connect on ping</param>
/// <param name="configuration">The configuration.</param>
/// <param name="isCritical">if set to <c>true</c> [is critical Resource].</param>
public ActiveMqPingMonitor(
string resourceName,
IConnectionFactory connectionFactory,
string queueName,
IResourceMonitorConfiguration configuration,
ILogger<ResourceMonitor> logger,
bool isCritical = false)
: base(
resourceName ?? "ActiveMQ",
new ActiveMqPingHealthCheckStrategy(connectionFactory),
new ActiveMqPingHealthCheckStrategy(connectionFactory, queueName),
configuration,
logger,
isCritical)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Apache.NMS.ActiveMQ" Version="1.7.1" />
<PackageReference Include="Apache.NMS.ActiveMQ" Version="1.7.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="1.1.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public class ActiveMqPingHealthCheckStrategyTests
private class Fixture
{
public IConnectionFactory ConnectionFactory { get; set; } = Substitute.For<IConnectionFactory>();
public string DestinationQueueName { get; set; } = "pingQueue";

public ActiveMqPingHealthCheckStrategy GetSut()
{
return new ActiveMqPingHealthCheckStrategy(ConnectionFactory);
return new ActiveMqPingHealthCheckStrategy(ConnectionFactory, DestinationQueueName);
}
}

Expand Down Expand Up @@ -83,7 +84,7 @@ public async Task Check_SendMessage_ReturnsTrue()

_fixture.ConnectionFactory.CreateConnection().Returns(connection);
connection.CreateSession().Returns(session);
session.CreateProducer(Arg.Any<IDestination>()).Returns(producer);
session.CreateProducer(Arg.Is<IQueue>(destination => destination.QueueName == _fixture.DestinationQueueName)).Returns(producer);

var target = _fixture.GetSut();
var result = await target.Check(CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 218c55d

Please sign in to comment.