Skip to content

Commit

Permalink
Merge pull request #27 from atidev/BILL-135098
Browse files Browse the repository at this point in the history
Add nullable annotation, file scoped and access modifier was fixed
  • Loading branch information
AlexFate authored Aug 2, 2024
2 parents 97843bc + 9770679 commit 468141d
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 198 deletions.
2 changes: 2 additions & 0 deletions ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>atisu.services.rabbitmq</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<NoWarn>1701;1702;CS1591;CS1571;CS1573;CS1574</NoWarn>
Expand Down
202 changes: 104 additions & 98 deletions ATI.Services.RabbitMQ/EventbusManager.cs

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions ATI.Services.RabbitMQ/EventbusOptions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;

namespace ATI.Services.RabbitMQ
namespace ATI.Services.RabbitMQ;

public class EventbusOptions
{
public class EventbusOptions
{
public string ServiceName { get; set; }
public string ConnectionString { get; set; }
public string Environment { get; set; }
public TimeSpan RabbitConnectInterval { get; set; } = TimeSpan.FromSeconds(5);
public bool Enabled { get; set; }
public string ErrorQueueName { get; set; }
public required string ServiceName { get; init; }
public required string ConnectionString { get; init; }
public required string Environment { get; init; }
public required TimeSpan RabbitConnectInterval { get; set; } = TimeSpan.FromSeconds(5);
public required bool Enabled { get; init; }
public string? ErrorQueueName { get; init; }

#region ForLocalTesting
#region ForLocalTesting

public bool AddHostnamePostfixToQueues { get; set; }
public bool DeleteQueuesOnApplicationShutdown { get; set; }
public bool AddHostnamePostfixToQueues { get; init; }
public bool DeleteQueuesOnApplicationShutdown { get; init; }

#endregion
}
#endregion
}
14 changes: 7 additions & 7 deletions ATI.Services.RabbitMQ/ExchangeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace ATI.Services.RabbitMQ
// ReSharper disable PropertyCanBeMadeInitOnly.Global
namespace ATI.Services.RabbitMQ;

public class ExchangeInfo
{
public class ExchangeInfo
{
public string Name { get; set; }
public string Type { get; set; }
}
}
public required string Name { get; set; }
public required string Type { get; set; }
}
13 changes: 6 additions & 7 deletions ATI.Services.RabbitMQ/IEventbusEntity.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using JetBrains.Annotations;

namespace ATI.Services.RabbitMQ
namespace ATI.Services.RabbitMQ;

[PublicAPI]
public interface IEventbusEntity
{
[PublicAPI]
public interface IEventbusEntity
{
string GetRoutingKey(string action);
}
}
string GetRoutingKey(string action);
}
23 changes: 11 additions & 12 deletions ATI.Services.RabbitMQ/Operation.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using JetBrains.Annotations;

namespace ATI.Services.RabbitMQ
namespace ATI.Services.RabbitMQ;

[PublicAPI]
public static class Operation
{
[PublicAPI]
public static class Operation
{
public const string Change = "changed";
public const string Update = "u";
public const string Insert = "i";
public const string Delete = "d";
public const string BeforeUpdate = "beforeUpdate";
public const string Any = "*";
}
}
public const string Change = "changed";
public const string Update = "u";
public const string Insert = "i";
public const string Delete = "d";
public const string BeforeUpdate = "beforeUpdate";
public const string Any = "*";
}
10 changes: 6 additions & 4 deletions ATI.Services.RabbitMQ/QueueExchangeBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class QueueExchangeBinding(
Queue queue,
string routingKey,
string queueType = QueueType.Quorum,
Action<IQueueDeclareConfiguration> queueConfiguration = null,
Action<ISimpleConsumeConfiguration> consumerConfiguration = null)
Action<IQueueDeclareConfiguration>? queueConfiguration = null,
Action<ISimpleConsumeConfiguration>? consumerConfiguration = null)
{
//for back compatibility release
[Obsolete("Use constructor with queueConfiguration and consumerConfiguration")]
Expand All @@ -28,13 +28,15 @@ public QueueExchangeBinding(ExchangeInfo exchange,
public string RoutingKey { get; } = routingKey;
public ExchangeInfo Exchange { get; } = exchange;
public string QueueType { get; } = queueType;

/// <summary>
/// Configuration for queue declare
/// This configuration will be overriden by params in SubscribeAsync method
/// </summary>
public Action<IQueueDeclareConfiguration> QueueConfiguration { get; } = queueConfiguration;
public Action<IQueueDeclareConfiguration>? QueueConfiguration { get; } = queueConfiguration;

/// <summary>
/// Configuration for consumer
/// </summary>
public Action<ISimpleConsumeConfiguration> ConsumerConfiguration { get; } = consumerConfiguration;
public Action<ISimpleConsumeConfiguration>? ConsumerConfiguration { get; } = consumerConfiguration;
}
19 changes: 9 additions & 10 deletions ATI.Services.RabbitMQ/RMQTopology.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public QueueExchangeBinding CreateBinding(
bool isDurable,
bool isAutoDelete,
bool isExclusiveQueueName = false,
string customQueueName = null,
string entityName = null,
string? customQueueName = null,
string? entityName = null,
string queueType = QueueType.Quorum,
Action<IQueueDeclareConfiguration> queueConfiguration = null,
Action<ISimpleConsumeConfiguration> consumerConfiguration = null)
Action<IQueueDeclareConfiguration>? queueConfiguration = null,
Action<ISimpleConsumeConfiguration>? consumerConfiguration = null)
{
var queueName =
EventbusQueueNameTemplate(exchangeName, routingKey, customQueueName, isExclusiveQueueName,
Expand All @@ -63,9 +63,9 @@ public QueueExchangeBinding CreateBinding(
private string EventbusQueueNameTemplate(
string rabbitService,
string routingKey,
string customQueueName,
string? customQueueName,
bool isExclusiveQueueName,
string entityName = null)
string? entityName = null)
{
var exchangeNameWithoutEnv = entityName;
if (exchangeNameWithoutEnv is null)
Expand All @@ -75,13 +75,12 @@ private string EventbusQueueNameTemplate(
if (string.IsNullOrEmpty(exchangeNameWithoutEnv))
exchangeNameWithoutEnv = rabbitService;
}
var queueSuffix = customQueueName.IsNullOrEmpty()

var queueSuffix = string.IsNullOrEmpty(customQueueName)
? $"{_eventbusOptions.ServiceName}.{exchangeNameWithoutEnv}.{routingKey}"
: customQueueName;

var queueName = $"{_eventbusOptions.Environment}.{SubscriptionType}.{queueSuffix}";

var queueName = $"{_eventbusOptions.Environment}.{SubscriptionType}.{queueSuffix}";

if (_eventbusOptions.AddHostnamePostfixToQueues || isExclusiveQueueName)
queueName += _queuePostfixName;
Expand Down
19 changes: 9 additions & 10 deletions ATI.Services.RabbitMQ/RabbitMQConventions.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using EasyNetQ;

namespace ATI.Services.RabbitMQ
namespace ATI.Services.RabbitMQ;

public class RabbitMqConventions : Conventions
{
public class RabbitMqConventions : Conventions
public RabbitMqConventions(ITypeNameSerializer typeNameSerializer, EventbusOptions options) :
base(typeNameSerializer)
{
public RabbitMqConventions(ITypeNameSerializer typeNameSerializer, EventbusOptions options) :
base(typeNameSerializer)
{
ErrorExchangeNamingConvention = _ => "Services_Default_Error_Exchange";
ErrorQueueNamingConvention = _ => !string.IsNullOrEmpty(options.ErrorQueueName)
? options.ErrorQueueName
: "Services_Default_Error_Queue";
}
ErrorExchangeNamingConvention = _ => "Services_Default_Error_Exchange";
ErrorQueueNamingConvention = _ => !string.IsNullOrEmpty(options.ErrorQueueName)
? options.ErrorQueueName
: "Services_Default_Error_Queue";
}
}
9 changes: 4 additions & 5 deletions ATI.Services.RabbitMQ/RabbitMqDeclaredQueues.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using EasyNetQ.Topology;

namespace ATI.Services.RabbitMQ
namespace ATI.Services.RabbitMQ;

public static class RabbitMqDeclaredQueues
{
public static class RabbitMqDeclaredQueues
{
public static List<Queue> DeclaredQueues { get; } = new();
}
public static List<Queue> DeclaredQueues { get; } = [];
}
29 changes: 14 additions & 15 deletions ATI.Services.RabbitMQ/RabbitMqExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;

namespace ATI.Services.RabbitMQ
namespace ATI.Services.RabbitMQ;

public static class RabbitMqExtensions
{
public static class RabbitMqExtensions
[PublicAPI]
public static void AddEventBus(this IServiceCollection services, string? eventbusSectionName = null)
{
[PublicAPI]
public static void AddEventBus(this IServiceCollection services, string eventbusSectionName = null)
if (eventbusSectionName is null)
{
if (eventbusSectionName != null)
{
services.Configure<EventbusOptions>(ConfigurationManager.GetSection(eventbusSectionName));
}
else
{
services.ConfigureByName<EventbusOptions>();
}

services.AddSingleton<EventbusManager>();
services.AddSingleton<RmqTopology>();
services.ConfigureByName<EventbusOptions>();
}
else
{
services.Configure<EventbusOptions>(ConfigurationManager.GetSection(eventbusSectionName));
}

services.AddSingleton<EventbusManager>();
services.AddSingleton<RmqTopology>();
}
}
19 changes: 9 additions & 10 deletions ATI.Services.RabbitMQ/RoutingKeys.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using JetBrains.Annotations;

namespace ATI.Services.RabbitMQ
namespace ATI.Services.RabbitMQ;

[PublicAPI]
public static class RoutingKeys
{
[PublicAPI]
public static class RoutingKeys
{
public const string Created = "created";
public const string Inserted = "inserted";
public const string Updated = "updated";
public const string Deleted = "deleted";
public const string Restored = "restored";
}
public const string Created = "created";
public const string Inserted = "inserted";
public const string Updated = "updated";
public const string Deleted = "deleted";
public const string Restored = "restored";
}
13 changes: 7 additions & 6 deletions ATI.Services.RabbitMQ/SubscriptionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
// ReSharper disable PropertyCanBeMadeInitOnly.Global
using System;
using System.Threading.Tasks;
using EasyNetQ;
using EasyNetQ.Consumer;
Expand All @@ -7,13 +8,13 @@ namespace ATI.Services.RabbitMQ;

public class SubscriptionInfo
{
public QueueExchangeBinding Binding { get; set; }
public required QueueExchangeBinding Binding { get; set; }

public Func<byte[], MessageProperties, MessageReceivedInfo, Task<AckStrategy>> EventbusSubscriptionHandler { get; set; }
public Func<byte[], MessageProperties, MessageReceivedInfo, Task<AckStrategy>>? EventbusSubscriptionHandler { get; set; }

public string MetricsEntity { get; set; }
public IDisposable Consumer { get; set; }
public string? MetricsEntity { get; set; }
public required IDisposable Consumer { get; set; }

public Task ResubscribeTask { get; set; }
public Task? ResubscribeTask { get; set; }
public object ResubscribeLock { get; } = new();
}

0 comments on commit 468141d

Please sign in to comment.