[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)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Services.GraphQL;
|
||||
|
||||
public class LoggingErrorFilter : IErrorFilter
|
||||
{
|
||||
private readonly ILogger<LoggingErrorFilter> _logger;
|
||||
|
||||
public LoggingErrorFilter(ILogger<LoggingErrorFilter> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IError OnError(IError error)
|
||||
{
|
||||
if (error.Exception != null)
|
||||
{
|
||||
_logger.LogError(error.Exception, "Unexpected GraphQL error occurred");
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user