Files
components/LiteCharms.Infrastructure/ServiceBus/Exchanges/EmailExchange.cs
T
Khwezi Mngoma cecd9f90e9
continuous-integration/drone/pr Build is passing
Implemented service bus handling of emails and notification processing
2026-05-10 16:50:36 +02:00

38 lines
1.3 KiB
C#

using LiteCharms.Infrastructure.ServiceBus.Queues;
namespace LiteCharms.Infrastructure.ServiceBus.Exchanges;
public class EmailExchange(EmailQueue messages, ILogger<EmailExchange> logger, IPublisher mediator) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
while (messages.Incoming.TryRead(out var message))
{
try
{
switch (message.Name)
{
case "SendShopEmailEnquiryEvent":
await mediator.Publish(message, stoppingToken);
break;
case "ProcessEmailNotificationsEvent":
await mediator.Publish(message, stoppingToken);
break;
default:
logger.LogWarning("Unsupported email event {Event}", message.Name);
break;
}
}
catch (Exception ex)
{
logger.LogError(ex, ex.Message);
}
}
await Task.Delay(1000, stoppingToken);
}
}
}