Implemented service bus handling of emails and notification processing
continuous-integration/drone/pr Build is passing
continuous-integration/drone/pr Build is passing
This commit is contained in:
@@ -89,10 +89,11 @@
|
||||
<ProjectReference Include="..\LiteCharms.Models\LiteCharms.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Global Usings -->
|
||||
<!-- Global Shared Usings -->
|
||||
<ItemGroup>
|
||||
<Using Include="System.Text.Json" />
|
||||
<Using Include="Microsoft.Extensions.Hosting" />
|
||||
<Using Include="Microsoft.Extensions.Logging" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user