Refactor RabbitMQ connection handling logic

Updated `OutgoingEmailConsumer` and `OutgoingEmailPublisher` to use `GetDefaultConnectionAsync` instead of `GetConnectionAsync` for initializing RabbitMQ connections.

Renamed `GetConnectionAsync` to `GetDefaultConnectionAsync` in `RabbitMqConnectionFactory` to improve clarity and align with naming conventions. Updated `InitAsync` in `RabbitMqConnectionFactory` to use the renamed method.

These changes improve consistency, maintainability, and clarity in RabbitMQ connection management.
This commit is contained in:
2026-07-27 13:05:17 +02:00
parent 3611d527d4
commit a2373f242a
3 changed files with 4 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ public sealed class OutgoingEmailConsumer(IOptions<RabbitMqConfiguration> config
/// </summary> /// </summary>
public async Task InitAsync() public async Task InitAsync()
{ {
var connection = await CnnFactory.GetConnectionAsync(); var connection = await CnnFactory.GetDefaultConnectionAsync();
var stoppingToken = CnnFactory.CancellationToken; var stoppingToken = CnnFactory.CancellationToken;

View File

@@ -28,7 +28,7 @@ public sealed class OutgoingEmailPublisher(IOptions<RabbitMqConfiguration> confi
/// </summary> /// </summary>
public async Task InitAsync() public async Task InitAsync()
{ {
var connection = await CnnFactory.GetConnectionAsync(); var connection = await CnnFactory.GetDefaultConnectionAsync();
var stoppingToken = CnnFactory.CancellationToken; var stoppingToken = CnnFactory.CancellationToken;

View File

@@ -30,7 +30,7 @@ namespace DigitalData.MessagingService.RabbitMQ
public CancellationToken CancellationToken => _cancellationToken public CancellationToken CancellationToken => _cancellationToken
?? throw new InvalidOperationException("RabbitMqConnectionFactory is not initialized. Call InitAsync() before using this method."); ?? throw new InvalidOperationException("RabbitMqConnectionFactory is not initialized. Call InitAsync() before using this method.");
public Task<IConnection> GetConnectionAsync() public Task<IConnection> GetDefaultConnectionAsync()
{ {
if (_cancellationToken != null) if (_cancellationToken != null)
return _lazyConnectionProvider.Value; return _lazyConnectionProvider.Value;
@@ -67,7 +67,7 @@ namespace DigitalData.MessagingService.RabbitMQ
public async Task InitAsync(CancellationToken cancellationToken = default) public async Task InitAsync(CancellationToken cancellationToken = default)
{ {
_cancellationToken = cancellationToken; _cancellationToken = cancellationToken;
_ = await GetConnectionAsync(); _ = await GetDefaultConnectionAsync();
} }
public async ValueTask DisposeAsync() public async ValueTask DisposeAsync()