public async Task PublishEventsThroughEventBusAsync() { var events = await _outboxEventService.RetrieveFailedEventsToPublishAsync(); foreach (var @event in events) { _logger.LogInformation( "----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.EventId, @event.IntegrationEvent); try { await _outboxEventService.MarkEventAsInProgressAsync(@event.EventId); await _bus.Publish(@event.IntegrationEvent, @event.IntegrationEvent.GetType()); await _outboxEventService.MarkEventAsPublishedAsync(@event.EventId); } catch (Exception ex) { _logger.LogError(ex, "ERROR publishing integration event: {IntegrationEventId}", @event.EventId); await _outboxEventService.MarkEventAsFailedAsync(@event.EventId); } } }
public async Task PublishEventsThroughEventBusAsync(Guid transactionId) { var pendingLogEvents = await _outboxEventService.RetrievePendingEventsToPublishAsync(transactionId); foreach (var logEvt in pendingLogEvents) { _logger.LogInformation( "----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", logEvt.EventId, logEvt.IntegrationEvent); try { await _outboxEventService.MarkEventAsInProgressAsync(logEvt.EventId); await _publishEndpoint.Publish(logEvt.IntegrationEvent, logEvt.IntegrationEvent.GetType()); await _outboxEventService.MarkEventAsPublishedAsync(logEvt.EventId); } catch (Exception ex) { _logger.LogError(ex, "ERROR publishing integration event: {IntegrationEventId}", logEvt.EventId); await _outboxEventService.MarkEventAsFailedAsync(logEvt.EventId); } } }