public async Task PublishEventsAsync(Guid transactionId) { var pendingEventLogs = await _integrationEventLogService.GetPendingEventLogEntries(transactionId); foreach (var eventLog in pendingEventLogs) { try { await _integrationEventLogService.MarkEventAsInProgressAsync(eventLog.EventId); _eventBus.Publish(eventLog.IntegrationEvent); await _integrationEventLogService.MarkEventAsPublishedAsync(eventLog.EventId); } catch (Exception ex) { Debug.WriteLine("Error publishing"); await _integrationEventLogService.MarkEventAsFailedAsync(eventLog.EventId); } } }