[FA-4] Adds an event bus infrastructure, a RabbitMQ implementation and rewires existing mutations on NovelService to utilize it.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using FictionArchive.Service.TranslationService.Models.Enums;
|
||||
using FictionArchive.Service.TranslationService.Models.IntegrationEvents;
|
||||
|
||||
namespace FictionArchive.Service.TranslationService.Services.EventHandlers;
|
||||
|
||||
public class TranslationRequestCreatedEventHandler : IIntegrationEventHandler<TranslationRequestCreatedEvent>
|
||||
{
|
||||
private readonly ILogger<TranslationRequestCreatedEventHandler> _logger;
|
||||
private readonly TranslationEngineService _translationEngineService;
|
||||
private readonly IEventBus _eventBus;
|
||||
|
||||
public TranslationRequestCreatedEventHandler(ILogger<TranslationRequestCreatedEventHandler> logger, TranslationEngineService translationEngineService)
|
||||
{
|
||||
_logger = logger;
|
||||
_translationEngineService = translationEngineService;
|
||||
}
|
||||
|
||||
public async Task Handle(TranslationRequestCreatedEvent @event)
|
||||
{
|
||||
var result = await _translationEngineService.Translate(@event.From, @event.To, @event.Body, @event.TranslationEngineKey);
|
||||
if (result.Status == TranslationRequestStatus.Success)
|
||||
{
|
||||
await _eventBus.Publish(new TranslationRequestCompletedEvent()
|
||||
{
|
||||
TranslatedText = result.TranslatedText,
|
||||
TranslationRequestId = @event.TranslationRequestId,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user