protected async Task Move(ReceiveContext context, Action <InMemoryTransportMessage, SendHeaders> preSend) { var messageId = GetMessageId(context); byte[] body = context.GetBody(); var messageType = "Unknown"; if (context.TryGetPayload(out InMemoryTransportMessage receivedMessage)) { messageType = receivedMessage.MessageType; } var transportMessage = new InMemoryTransportMessage(messageId, body, context.ContentType.MediaType, messageType); SendHeaders headers = new DictionarySendHeaders(transportMessage.Headers); headers.SetHostHeaders(); preSend(transportMessage, headers); transportMessage.Headers[MessageHeaders.Reason] = "dead-letter"; await _exchange.Send(transportMessage).ConfigureAwait(false); }
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)); }