static void ConvertToPendingOperations(OutboxMessage deduplicationEntry, PendingTransportOperations pendingTransportOperations) { foreach (var operation in deduplicationEntry.TransportOperations) { var message = new OutgoingMessage(operation.MessageId, operation.Headers, operation.Body); pendingTransportOperations.Add( new Transport.TransportOperation( message, DeserializeRoutingStrategy(operation.Options), DispatchConsistency.Isolated, DeserializeConstraints(operation.Options))); } }
public async Task Invoke(ITransportReceiveContext context, Func <IIncomingPhysicalMessageContext, Task> next) { var messageId = context.Message.MessageId; var physicalMessageContext = this.CreateIncomingPhysicalMessageContext(context.Message, context); var deduplicationEntry = await outboxStorage.Get(messageId, context.Extensions).ConfigureAwait(false); var pendingTransportOperations = new PendingTransportOperations(); if (deduplicationEntry == null) { physicalMessageContext.Extensions.Set(pendingTransportOperations); using (var outboxTransaction = await outboxStorage.BeginTransaction(context.Extensions).ConfigureAwait(false)) { context.Extensions.Set(outboxTransaction); await next(physicalMessageContext).ConfigureAwait(false); var outboxMessage = new OutboxMessage(messageId, ConvertToOutboxOperations(pendingTransportOperations.Operations)); await outboxStorage.Store(outboxMessage, outboxTransaction, context.Extensions).ConfigureAwait(false); context.Extensions.Remove <OutboxTransaction>(); await outboxTransaction.Commit().ConfigureAwait(false); } physicalMessageContext.Extensions.Remove <PendingTransportOperations>(); } else { ConvertToPendingOperations(deduplicationEntry, pendingTransportOperations); } if (pendingTransportOperations.HasOperations) { var batchDispatchContext = this.CreateBatchDispatchContext(pendingTransportOperations.Operations, physicalMessageContext); await this.Fork(batchDispatchContext).ConfigureAwait(false); } await outboxStorage.SetAsDispatched(messageId, context.Extensions).ConfigureAwait(false); }