public async Task PublishEventsThroughEventBusAsync(Guid transactionId) { var pendingLogEvents = await RetrieveEventLogsPendingToPublishAsync(transactionId); foreach (var logEvt in pendingLogEvents) { // _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", logEvt.EventId, Program.AppName, logEvt.IntegrationEvent); try { await MarkEventAsInProgressAsync(logEvt.MessageId); var deserializedObject = logEvt.Content.DeserializeJson(); await _endpoint.Publish(deserializedObject, logEvt.MessageId); await MarkEventAsPublishedAsync(logEvt.MessageId); } catch (Exception ex) { //_logger.LogError(ex, "ERROR publishing integration event: {IntegrationEventId} from {AppName}", logEvt.EventId, Program.AppName); await MarkEventAsFailedAsync(logEvt.MessageId); } } }
private async Task ProccessEvents() { List <IntegrationEventLog> localIntegrationEvents = await _integrationEventLogRepository.GetAllReadyToPulishAndUpdateTheirStatuses(); foreach (var @event in localIntegrationEvents) { object obj = @event.Content.DeserializeJson(); var messageId = @event.MessageId; await _endpoint.Publish(obj, messageId).ConfigureAwait(false); @event.State = EventStateEnum.Published; await _integrationEventLogRepository.UpdateAsync(@event); await _integrationEventLogRepository.UnitOfWork.SaveChangesAsync(); } }