Implemented service bus handling of emails and notification processing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Khwezi Mngoma
2026-05-10 16:50:36 +02:00
parent 73ba41beaf
commit cecd9f90e9
6 changed files with 90 additions and 11 deletions
@@ -2,11 +2,36 @@
namespace LiteCharms.Infrastructure.ServiceBus.Exchanges;
public class EmailExchange(EmailQueue messages) : BackgroundService
public class EmailExchange(EmailQueue messages, ILogger<EmailExchange> logger, IPublisher mediator) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if(messages.Incoming.CanCount)
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);
}
}
}