Moved RabbitMQ-related functionality from the `DigitalData.MessagingService.Infrastructure` project to a new dedicated project/namespace `DigitalData.MessagingService.RabbitMQ`. - Updated `DependencyInjection.cs` to use the new namespace. - Added a project reference to `RabbitMQ.csproj` in the `Infrastructure.csproj` file. - Removed `RabbitMqConfiguration.cs` and `RabbitMqConnectionFactory.cs` from the `Infrastructure` project. - Updated namespaces in `OutgoingEmailConsumer.cs`, `OutgoingEmailPublisher.cs`, and `AsyncInitWorker.cs` to use `DigitalData.MessagingService.RabbitMQ`. This refactor improves modularity, maintainability, and separation of concerns by isolating RabbitMQ functionality in its own project.
27 lines
1.3 KiB
C#
27 lines
1.3 KiB
C#
using DigitalData.MessagingService.Application.Common.Interfaces;
|
|
using DigitalData.MessagingService.Infrastructure.Queue;
|
|
using DigitalData.MessagingService.RabbitMQ;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace DigitalData.MessagingService.Infrastructure.Services.Background;
|
|
|
|
/// <summary>
|
|
/// A hosted background service responsible for initializing the outgoing email queue consumer.
|
|
/// Leverages a push-based, event-driven RabbitMQ consumer to eliminate polling overhead.
|
|
/// Email account configuration is resolved exclusively from application settings; no database access is performed.
|
|
/// </summary>
|
|
public class AsyncInitWorker(OutgoingEmailConsumer EmailConsumer, IOutgoingEmailPublisher EmailPublisher, RabbitMqConnectionFactory CnnFactory) : BackgroundService
|
|
{
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
// Initialize the RabbitMQ push-based consumer. This call is non-blocking;
|
|
// message processing is handled asynchronously via registered event callbacks.
|
|
await CnnFactory.InitAsync(stoppingToken);
|
|
|
|
await EmailConsumer.InitAsync();
|
|
|
|
if (EmailPublisher is OutgoingEmailPublisher emailPublisher)
|
|
await emailPublisher.InitAsync();
|
|
}
|
|
} |