protected Task Move(ReceiveContext context, Action <BrokeredMessage, SendHeaders> preSend) { IPipe <SendEndpointContext> clientPipe = Pipe.ExecuteAsync <SendEndpointContext>(async clientContext => { if (!context.TryGetPayload(out BrokeredMessageContext messageContext)) { throw new ArgumentException("The ReceiveContext must contain a BrokeredMessageContext (from Azure Service Bus)", nameof(context)); } using (var messageBodyStream = context.GetBodyStream()) using (var message = new BrokeredMessage(messageBodyStream) { ContentType = context.ContentType.MediaType, ForcePersistence = messageContext.ForcePersistence, TimeToLive = messageContext.TimeToLive, CorrelationId = messageContext.CorrelationId, MessageId = messageContext.MessageId, Label = messageContext.Label, PartitionKey = messageContext.PartitionKey, ReplyTo = messageContext.ReplyTo, ReplyToSessionId = messageContext.ReplyToSessionId, SessionId = messageContext.SessionId }) { SendHeaders headers = new DictionarySendHeaders(message.Properties); foreach (KeyValuePair <string, object> property in messageContext.Properties) { headers.Set(property.Key, property.Value); } headers.SetHostHeaders(); preSend(message, headers); await clientContext.Send(message).ConfigureAwait(false); var reason = message.Properties.ContainsKey(MessageHeaders.Reason) ? message.Properties[MessageHeaders.Reason].ToString() : ""; if (reason == "fault") { reason = message.Properties.ContainsKey(MessageHeaders.FaultMessage) ? $"Fault: {message.Properties[MessageHeaders.FaultMessage]}" : "Fault"; } context.LogMoved(clientContext.EntityPath, reason); } }); return(_source.Send(clientPipe, context.CancellationToken)); }
protected Task Move(ReceiveContext context, Action <Message, IDictionary <string, object> > preSend) { IPipe <SendEndpointContext> clientPipe = Pipe.ExecuteAsync <SendEndpointContext>(async clientContext => { if (!context.TryGetPayload(out BrokeredMessageContext messageContext)) { throw new ArgumentException("The ReceiveContext must contain a BrokeredMessageContext (from Azure Service Bus)", nameof(context)); } using (var messageBodyStream = context.GetBodyStream()) { var message = new Message(messageBodyStream.ReadAsBytes()) { ContentType = context.ContentType.MediaType, TimeToLive = messageContext.TimeToLive, CorrelationId = messageContext.CorrelationId, MessageId = messageContext.MessageId, Label = messageContext.Label, PartitionKey = messageContext.PartitionKey, ReplyTo = messageContext.ReplyTo, ReplyToSessionId = messageContext.ReplyToSessionId, SessionId = messageContext.SessionId }; foreach (KeyValuePair <string, object> property in messageContext.Properties.Where(x => !x.Key.StartsWith("MT-"))) { message.UserProperties.Set(new HeaderValue(property.Key, property.Value)); } message.UserProperties.SetHostHeaders(); preSend(message, message.UserProperties); await clientContext.Send(message).ConfigureAwait(false); var reason = message.UserProperties.TryGetValue(MessageHeaders.Reason, out var reasonProperty) ? reasonProperty.ToString() : ""; if (reason == "fault") { reason = message.UserProperties.TryGetValue(MessageHeaders.FaultMessage, out var fault) ? $"Fault: {fault}" : "Fault"; } context.LogMoved(clientContext.EntityPath, reason); } }); return(_supervisor.Send(clientPipe, context.CancellationToken)); }