Skip to content

Commit

Permalink
Добавил опцию EnableConsoleLogger в EventbusOption (#28)
Browse files Browse the repository at this point in the history
* Add option for local testing
  • Loading branch information
alan-kh authored Nov 7, 2024
1 parent 468141d commit 0020680
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<NoWarn>1701;1702;CS1591;CS1571;CS1573;CS1574</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="atisu.services.common" Version="16.4.0" />
<PackageReference Include="EasyNetQ" Version="7.4.3" />
<PackageReference Include="atisu.services.common" Version="16.8.0" />
<PackageReference Include="EasyNetQ" Version="7.8.0" />
</ItemGroup>
</Project>
25 changes: 20 additions & 5 deletions ATI.Services.RabbitMQ/EventbusManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public Task InitializeAsync()
serviceRegister =>
{
serviceRegister.Register<IConventions>(c =>
new RabbitMqConventions(c.Resolve<ITypeNameSerializer>(), _options));
new RabbitMqConventions(c.Resolve<ITypeNameSerializer>(), _options)
);

if (_options.EnableConsoleLogger)
serviceRegister.EnableConsoleLogger();
}).Advanced;

_busClient.Connected += (_, _) => ResubscribeOnReconnect();
Expand Down Expand Up @@ -173,7 +177,8 @@ await _busClient.PublishAsync(
routingKey,
mandatory,
messageProperties,
body)
body
)
);

if (sendingResult.FinalException != null)
Expand Down Expand Up @@ -235,10 +240,20 @@ public Task SubscribeAsync(QueueExchangeBinding bindingInfo,
}));
}

private static AsyncPolicyWrap SetupPolicy(TimeSpan? timeout = null) =>
Policy.WrapAsync(Policy.TimeoutAsync(timeout ?? TimeSpan.FromSeconds(2)),
private AsyncPolicyWrap SetupPolicy(TimeSpan? timeout = null) =>
Policy.WrapAsync(
Policy.TimeoutAsync(timeout ?? TimeSpan.FromSeconds(3)),
Policy.Handle<Exception>()
.WaitAndRetryAsync(3, _ => TimeSpan.FromSeconds(3)));
.WaitAndRetryAsync(
3,
_ => TimeSpan.FromSeconds(1),
(exception, timeSpan, retryCount, _) =>
{
if(_options.LogInnerExceptionsInRetryPolicy)
_logger.ErrorWithObject(exception, new { TimeSpan = timeSpan, RetryCount = retryCount });
}
)
);

private async Task<Acknowledgements> ExecuteWithPolicy(Func<Task<Acknowledgements>> action)
{
Expand Down
2 changes: 2 additions & 0 deletions ATI.Services.RabbitMQ/EventbusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class EventbusOptions

public bool AddHostnamePostfixToQueues { get; init; }
public bool DeleteQueuesOnApplicationShutdown { get; init; }
public bool EnableConsoleLogger { get; init; }
public bool LogInnerExceptionsInRetryPolicy { get; init; }

#endregion
}

0 comments on commit 0020680

Please sign in to comment.