[FA-9] Need to add persistence layer
This commit is contained in:
@@ -3,4 +3,5 @@ namespace FictionArchive.Service.Shared.Services.EventBus;
|
||||
public interface IEventBus
|
||||
{
|
||||
Task Publish<TEvent>(TEvent integrationEvent) where TEvent : IntegrationEvent;
|
||||
Task Publish(object integrationEvent, string eventType);
|
||||
}
|
||||
@@ -36,15 +36,20 @@ public class RabbitMQEventBus : IEventBus, IHostedService
|
||||
public async Task Publish<TEvent>(TEvent integrationEvent) where TEvent : IntegrationEvent
|
||||
{
|
||||
var routingKey = typeof(TEvent).Name;
|
||||
var channel = await _connectionProvider.GetDefaultChannelAsync();
|
||||
|
||||
// Set integration event values
|
||||
integrationEvent.CreatedAt = Instant.FromDateTimeUtc(DateTime.UtcNow);
|
||||
integrationEvent.EventId = Guid.NewGuid();
|
||||
|
||||
await Publish(integrationEvent, routingKey);
|
||||
}
|
||||
|
||||
public async Task Publish(object integrationEvent, string eventType)
|
||||
{
|
||||
var channel = await _connectionProvider.GetDefaultChannelAsync();
|
||||
var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(integrationEvent));
|
||||
await channel.BasicPublishAsync(ExchangeName, routingKey, true, body);
|
||||
_logger.LogInformation("Published event {EventName}", routingKey);
|
||||
await channel.BasicPublishAsync(ExchangeName, eventType, true, body);
|
||||
_logger.LogInformation("Published event {EventName}", eventType);
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user