Files
DigitalData.MessagingService/src/DigitalData.MessagingService.Infrastructure/Services/Background/AsyncInitWorker.cs
TekH 3611d527d4 Refactor RabbitMQ functionality to new project
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.
2026-07-27 13:03:39 +02:00

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();
}
}