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:
@@ -27,7 +27,7 @@ public sealed class OutgoingEmailConsumer(IOptions<RabbitMqConfiguration> config
|
||||
/// </summary>
|
||||
public async Task InitAsync()
|
||||
{
|
||||
var connection = await CnnFactory.GetConnectionAsync();
|
||||
var connection = await CnnFactory.GetDefaultConnectionAsync();
|
||||
|
||||
var stoppingToken = CnnFactory.CancellationToken;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public sealed class OutgoingEmailPublisher(IOptions<RabbitMqConfiguration> confi
|
||||
/// </summary>
|
||||
public async Task InitAsync()
|
||||
{
|
||||
var connection = await CnnFactory.GetConnectionAsync();
|
||||
var connection = await CnnFactory.GetDefaultConnectionAsync();
|
||||
|
||||
var stoppingToken = CnnFactory.CancellationToken;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace DigitalData.MessagingService.RabbitMQ
|
||||
public CancellationToken CancellationToken => _cancellationToken
|
||||
?? throw new InvalidOperationException("RabbitMqConnectionFactory is not initialized. Call InitAsync() before using this method.");
|
||||
|
||||
public Task<IConnection> GetConnectionAsync()
|
||||
public Task<IConnection> GetDefaultConnectionAsync()
|
||||
{
|
||||
if (_cancellationToken != null)
|
||||
return _lazyConnectionProvider.Value;
|
||||
@@ -67,7 +67,7 @@ namespace DigitalData.MessagingService.RabbitMQ
|
||||
public async Task InitAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
_cancellationToken = cancellationToken;
|
||||
_ = await GetConnectionAsync();
|
||||
_ = await GetDefaultConnectionAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
|
||||
Reference in New Issue
Block a user