Added abstractions
Internal service bus support enabled Added quartz support Reconfigured extensions
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using LiteCharms.Abstractions;
|
||||
using LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus;
|
||||
|
||||
public class EmailServiceBus(EmailQueue messages) : IEventBus
|
||||
{
|
||||
public async Task<Result> PublishAsync<TEvent>(TEvent notification, CancellationToken cancellationToken = default)
|
||||
where TEvent : class, IEvent
|
||||
{
|
||||
try
|
||||
{
|
||||
await messages.Outgoing.WriteAsync(notification, cancellationToken);
|
||||
|
||||
return Result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus.Exchanges;
|
||||
|
||||
public class EmailExchange(EmailQueue messages) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
if(messages.Incoming.CanCount)
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus.Exchanges;
|
||||
|
||||
public class GeneralExchange(GeneralQueue messages) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
if (messages.Incoming.CanCount)
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus.Exchanges;
|
||||
|
||||
public class SalesExchange(SalesQueue messages) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
if (messages.Incoming.CanCount)
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using LiteCharms.Abstractions;
|
||||
using LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus;
|
||||
|
||||
public class GeneralServiceBus(GeneralQueue messages) : IEventBus
|
||||
{
|
||||
public async Task<Result> PublishAsync<TEvent>(TEvent notification, CancellationToken cancellationToken = default)
|
||||
where TEvent : class, IEvent
|
||||
{
|
||||
try
|
||||
{
|
||||
await messages.Outgoing.WriteAsync(notification, cancellationToken);
|
||||
|
||||
return Result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using LiteCharms.Abstractions;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
public class EmailQueue : EventBusQueueBase, IEventBusQueue;
|
||||
@@ -0,0 +1,5 @@
|
||||
using LiteCharms.Abstractions;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
public class GeneralQueue : EventBusQueueBase, IEventBusQueue;
|
||||
@@ -0,0 +1,5 @@
|
||||
using LiteCharms.Abstractions;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
public class SalesQueue : EventBusQueueBase, IEventBusQueue;
|
||||
@@ -0,0 +1,22 @@
|
||||
using LiteCharms.Abstractions;
|
||||
using LiteCharms.Infrastructure.ServiceBus.Queues;
|
||||
|
||||
namespace LiteCharms.Infrastructure.ServiceBus;
|
||||
|
||||
public class SalesServiceBus(SalesQueue messages) : IEventBus
|
||||
{
|
||||
public async Task<Result> PublishAsync<TEvent>(TEvent notification, CancellationToken cancellationToken = default)
|
||||
where TEvent : class, IEvent
|
||||
{
|
||||
try
|
||||
{
|
||||
await messages.Outgoing.WriteAsync(notification, cancellationToken);
|
||||
|
||||
return Result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user