public async Task Dispatch(CancellationToken cancellationToken) { using (var outboxUnitOfWork = await _unitOfWorkFactory.Begin(cancellationToken)) { var entries = await outboxUnitOfWork.GetAllUnpublishedEntries(cancellationToken); _logger.LogDebug("Unpublished outbox entries: {EntryCount}", entries.Count); try { foreach (var entry in entries) { await _producer.Produce(entry); entry.MaskAsProcessed(); _logger.LogDebug(@"Published outbox message {MessageId}", entry.MessageId); } } catch (Exception exception) { _logger.LogDebug("Error while publishing outbox messages", exception); throw; } await outboxUnitOfWork.Commit(cancellationToken); } }
public async Task Dispatch(CancellationToken cancellationToken) { using (var outboxUnitOfWork = _unitOfWorkFactory.Begin()) { var outboxMessages = await outboxUnitOfWork.GetAllUnpublishedMessages(cancellationToken); Log.Debug("Unpublished outbox messages: {OutboxMessageCount}", outboxMessages.Count); try { foreach (var outboxMessage in outboxMessages) { await _producer.Produce(outboxMessage); outboxMessage.MaskAsProcessed(); Log.Debug(@"Published outbox message {MessageId} ({Type})", outboxMessage.MessageId, outboxMessage.Type); } } catch (Exception exception) { Log.Error("Error while publishing outbox messages", exception); throw; } await outboxUnitOfWork.Commit(cancellationToken); } }