Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp committed Aug 4, 2023
1 parent 035de9c commit 70c3f01
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 84 deletions.
24 changes: 0 additions & 24 deletions src/Messaging/API/IMessageBrokerSubscriberService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,6 @@ public interface IMessageBrokerSubscriberService : IDisposable
/// </summary>
string Name { get; }

/// <summary>
/// Subscribe to a message topic & queue and executes <c>messageReceivedCallback</c> for every message that is received.
/// Either provide a topic, a queue or both.
/// A queue is generated if the name of the queue is not provided.
/// </summary>
/// <param name="topic">Topic/routing key to bind to</param>
/// <param name="queue">Name of the queue to consume</param>
/// <param name="messageReceivedCallback">Action to be performed when message is received</param>
/// <param name="prefetchCount">Number of unacknowledged messages to receive at once. Defaults to 0.</param>
[Obsolete("This method is obsolete, use SubscribeAsync instead")]
void Subscribe(string topic, string queue, Action<MessageReceivedEventArgs> messageReceivedCallback, ushort prefetchCount = 0);

/// <summary>
/// Subscribe to a message topic & queue and executes <c>messageReceivedCallback</c> for every message that is received.
/// Either provide a topic, a queue or both.
/// A queue is generated if the name of the queue is not provided.
/// </summary>
/// <param name="topics">Topics/routing keys to bind to</param>
/// <param name="queue">Name of the queue to consume</param>
/// <param name="messageReceivedCallback">Action to be performed when message is received</param>
/// <param name="prefetchCount">Number of unacknowledged messages to receive at once. Defaults to 0.</param>
[Obsolete("This method is obsolete, use SubscribeAsync instead")]
void Subscribe(string[] topics, string queue, Action<MessageReceivedEventArgs> messageReceivedCallback, ushort prefetchCount = 0);

/// <summary>
/// Subscribe to a message topic & queue and executes <c>messageReceivedCallback</c> asynchronously for every message that is received.
/// Either provide a topic, a queue or both.
Expand Down
39 changes: 39 additions & 0 deletions src/Messaging/Common/ServiceException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Runtime.Serialization;

namespace Monai.Deploy.Messaging.Common
{
public class ServiceException : Exception

Check warning on line 21 in src/Messaging/Common/ServiceException.cs

View workflow job for this annotation

GitHub Actions / unit-test

Update this implementation of 'ISerializable' to conform to the recommended serialization pattern.

Check warning on line 21 in src/Messaging/Common/ServiceException.cs

View workflow job for this annotation

GitHub Actions / unit-test

Update this implementation of 'ISerializable' to conform to the recommended serialization pattern.
{
public ServiceException()
{
}

public ServiceException(string? message) : base(message)
{
}

public ServiceException(string? message, Exception? innerException) : base(message, innerException)
{
}

protected ServiceException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
6 changes: 3 additions & 3 deletions src/Messaging/Events/ExportCompleteEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public ExportCompleteEvent()

public ExportCompleteEvent(ExportRequestEvent exportRequest, ExportStatus exportStatus, Dictionary<string, FileExportStatus> fileStatuses)
{
Guard.Against.Null(exportRequest);
Guard.Against.Null(exportStatus);
Guard.Against.Null(fileStatuses);
Guard.Against.Null(exportRequest, nameof(exportRequest));
Guard.Against.Null(exportStatus, nameof(exportStatus));
Guard.Against.Null(fileStatuses, nameof(fileStatuses));

WorkflowInstanceId = exportRequest.WorkflowInstanceId;
ExportTaskId = exportRequest.ExportTaskId;
Expand Down
4 changes: 2 additions & 2 deletions src/Messaging/Monai.Deploy.Messaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Ardalis.GuardClauses" Version="4.0.1" />
<PackageReference Include="Ardalis.GuardClauses" Version="4.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.14" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.20" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
Expand Down
8 changes: 4 additions & 4 deletions src/Messaging/Tests/Monai.Deploy.Messaging.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
10 changes: 5 additions & 5 deletions src/Plugins/RabbitMQ/Factory/RabbitMqConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public RabbitMQConnectionFactory(ILogger<RabbitMQConnectionFactory> logger)

public IModel CreateChannel(ChannelType type, string hostName, string username, string password, string virtualHost, string useSSL, string portNumber)
{
Guard.Against.NullOrWhiteSpace(hostName);
Guard.Against.NullOrWhiteSpace(username);
Guard.Against.NullOrWhiteSpace(password);
Guard.Against.NullOrWhiteSpace(virtualHost);
Guard.Against.NullOrWhiteSpace(hostName, nameof(hostName));
Guard.Against.NullOrWhiteSpace(username, nameof(username));
Guard.Against.NullOrWhiteSpace(password, nameof(password));
Guard.Against.NullOrWhiteSpace(virtualHost, nameof(virtualHost));

var key = $"{type}{hostName}{username}{HashPassword(password)}{virtualHost}";

Expand Down Expand Up @@ -154,7 +154,7 @@ private IConnection CreateConnectionOnly(string hostName, string username, strin

private static object HashPassword(string password)
{
Guard.Against.NullOrWhiteSpace(password);
Guard.Against.NullOrWhiteSpace(password, nameof(password));
var sha256 = SHA256.Create();
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
return string.Join("", hash.Select(x => x.ToString("x2", CultureInfo.InvariantCulture)));
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/RabbitMQ/Monai.Deploy.Messaging.RabbitMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
<PackageReference Include="Polly" Version="7.2.4" />
<PackageReference Include="RabbitMQ.Client" Version="6.5.0" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public RabbitMQMessagePublisherService(IOptions<MessageBrokerServiceConfiguratio
ILogger<RabbitMQMessagePublisherService> logger,
IRabbitMQConnectionFactory rabbitMqConnectionFactory)
{
Guard.Against.Null(options);
Guard.Against.Null(options, nameof(options));

_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_rabbitMqConnectionFactory = rabbitMqConnectionFactory ?? throw new ArgumentNullException(nameof(rabbitMqConnectionFactory));
Expand Down Expand Up @@ -83,7 +83,7 @@ public RabbitMQMessagePublisherService(IOptions<MessageBrokerServiceConfiguratio

internal static void ValidateConfiguration(Dictionary<string, string> configuration)
{
Guard.Against.Null(configuration);
Guard.Against.Null(configuration, nameof(configuration));

foreach (var key in ConfigurationKeys.PublisherRequiredKeys)
{
Expand All @@ -96,8 +96,8 @@ internal static void ValidateConfiguration(Dictionary<string, string> configurat

public Task Publish(string topic, Message message)
{
Guard.Against.NullOrWhiteSpace(topic);
Guard.Against.Null(message);
Guard.Against.NullOrWhiteSpace(topic, nameof(topic));
Guard.Against.Null(message, nameof(message));

using var loggingScope = _logger.BeginScope(new LoggingDataDictionary<string, object>
{
Expand Down
51 changes: 21 additions & 30 deletions src/Plugins/RabbitMQ/Subscriber/RabbitMqMessageSubscriberService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public RabbitMQMessageSubscriberService(IOptions<MessageBrokerServiceConfigurati
ILogger<RabbitMQMessageSubscriberService> logger,
IRabbitMQConnectionFactory rabbitMqConnectionFactory)
{
Guard.Against.Null(options);
Guard.Against.Null(options, nameof(options));

_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_rabbitMqConnectionFactory = rabbitMqConnectionFactory ?? throw new ArgumentNullException(nameof(rabbitMqConnectionFactory));
Expand Down Expand Up @@ -109,7 +109,7 @@ private void CreateChannel()
.Execute(() =>
{
_logger.ConnectingToRabbitMQ(Name, _endpoint, _virtualHost);
_channel = _rabbitMqConnectionFactory.CreateChannel(ChannelType.Subscriber, _endpoint, _username, _password, _virtualHost, _useSSL, _portNumber);
_channel = _rabbitMqConnectionFactory.CreateChannel(ChannelType.Subscriber, _endpoint, _username, _password, _virtualHost, _useSSL, _portNumber) ?? throw new ServiceException("Failed to create a new channel to RabbitMQ");
_channel.ExchangeDeclare(_exchange, ExchangeType.Topic, durable: true, autoDelete: false);
_channel.ExchangeDeclare(_deadLetterExchange, ExchangeType.Topic, durable: true, autoDelete: false);
_channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
Expand Down Expand Up @@ -137,7 +137,7 @@ private void Channel_ModelShutdown(object? sender, ShutdownEventArgs e)

internal static void ValidateConfiguration(Dictionary<string, string> configuration)
{
Guard.Against.Null(configuration);
Guard.Against.Null(configuration, nameof(configuration));

foreach (var key in ConfigurationKeys.SubscriberRequiredKeys)
{
Expand All @@ -162,23 +162,14 @@ internal static void ValidateConfiguration(Dictionary<string, string> configurat
throw new ConfigurationException($"{ConfigurationKeys.SubscriberServiceName} has int values of less than 1");
}
}
[Obsolete("This method is obsolete, use SubscribeAsync instead")]
public void Subscribe(string topic, string queue, Action<MessageReceivedEventArgs> messageReceivedCallback, ushort prefetchCount = 0)
=> Subscribe(new string[] { topic }, queue, messageReceivedCallback, prefetchCount);

[Obsolete("This method is obsolete, use SubscribeAsync instead")]
public void Subscribe(string[] topics, string queue, Action<MessageReceivedEventArgs> messageReceivedCallback, ushort prefetchCount = 0)
{
SubscribeAsync(topics, queue, new Func<MessageReceivedEventArgs, Task>((args) => { messageReceivedCallback.Invoke(args); return Task.FromResult(0); }));
}

public void SubscribeAsync(string topic, string queue, Func<MessageReceivedEventArgs, Task> messageReceivedCallback, ushort prefetchCount = 0)
=> SubscribeAsync(new string[] { topic }, queue, messageReceivedCallback, prefetchCount);

public void SubscribeAsync(string[] topics, string queue, Func<MessageReceivedEventArgs, Task> messageReceivedCallback, ushort prefetchCount = 0)
{
Guard.Against.Null(topics);
Guard.Against.Null(messageReceivedCallback);
Guard.Against.Null(topics, nameof(topics));
Guard.Against.Null(messageReceivedCallback, nameof(messageReceivedCallback));

var queueDeclareResult = DeclareQueues(topics, queue, prefetchCount);
var consumer = CreateConsumer(messageReceivedCallback, queueDeclareResult);
Expand Down Expand Up @@ -212,7 +203,7 @@ private EventingBasicConsumer CreateConsumer(Func<MessageReceivedEventArgs, Task
_logger.InvalidMessage(queueDeclareResult.QueueName, eventArgs.RoutingKey, eventArgs.BasicProperties.MessageId, ex);
_logger.SendingNAcknowledgement(eventArgs.BasicProperties.MessageId);
_channel.BasicNack(eventArgs.DeliveryTag, multiple: false, requeue: false);
_channel!.BasicNack(eventArgs.DeliveryTag, multiple: false, requeue: false);
_logger.NAcknowledgementSent(eventArgs.BasicProperties.MessageId, false);
return;
}
Expand Down Expand Up @@ -273,7 +264,7 @@ private QueueDeclareOk DeclareQueues(string[] topics, string queue, ushort prefe

public void Acknowledge(MessageBase message)
{
Guard.Against.Null(message);
Guard.Against.Null(message, nameof(message));

CreateChannel();

Expand Down Expand Up @@ -305,7 +296,7 @@ public async Task RequeueWithDelay(MessageBase message)

public void Reject(MessageBase message, bool requeue = true)
{
Guard.Against.Null(message);
Guard.Against.Null(message, nameof(message));

CreateChannel();

Expand Down Expand Up @@ -344,8 +335,8 @@ public void Dispose()

private void BindToRoutingKeys(string[] topics, string queue, string deadLetterQueue = "")
{
Guard.Against.Null(topics);
Guard.Against.NullOrWhiteSpace(queue);
Guard.Against.Null(topics, nameof(topics));
Guard.Against.NullOrWhiteSpace(queue, nameof(queue));

foreach (var topic in topics)
{
Expand All @@ -363,17 +354,17 @@ private void BindToRoutingKeys(string[] topics, string queue, string deadLetterQ

private static MessageReceivedEventArgs CreateMessage(string topic, BasicDeliverEventArgs eventArgs)
{
Guard.Against.NullOrWhiteSpace(topic);
Guard.Against.Null(eventArgs);

Guard.Against.Null(eventArgs.Body);
Guard.Against.Null(eventArgs.BasicProperties);
Guard.Against.Null(eventArgs.BasicProperties.MessageId);
Guard.Against.Null(eventArgs.BasicProperties.AppId);
Guard.Against.Null(eventArgs.BasicProperties.ContentType);
Guard.Against.Null(eventArgs.BasicProperties.CorrelationId);
Guard.Against.Null(eventArgs.BasicProperties.Timestamp);
Guard.Against.Null(eventArgs.DeliveryTag);
Guard.Against.NullOrWhiteSpace(topic, nameof(topic));
Guard.Against.Null(eventArgs, nameof(eventArgs));

Guard.Against.Null(eventArgs.Body, nameof(eventArgs));
Guard.Against.Null(eventArgs.BasicProperties, nameof(eventArgs.BasicProperties));
Guard.Against.Null(eventArgs.BasicProperties.MessageId, nameof(eventArgs.BasicProperties.MessageId));
Guard.Against.Null(eventArgs.BasicProperties.AppId, nameof(eventArgs.BasicProperties.AppId));
Guard.Against.Null(eventArgs.BasicProperties.ContentType, nameof(eventArgs.BasicProperties.ContentType));
Guard.Against.Null(eventArgs.BasicProperties.CorrelationId, nameof(eventArgs.BasicProperties.CorrelationId));
Guard.Against.Null(eventArgs.BasicProperties.Timestamp, nameof(eventArgs.BasicProperties.Timestamp));
Guard.Against.Null(eventArgs.DeliveryTag, nameof(eventArgs.DeliveryTag));

return new MessageReceivedEventArgs(
new Message(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
~ Copyright 2022 MONAI Consortium
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -38,19 +38,19 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.14" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.20" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 70c3f01

Please sign in to comment.