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));
        }
        public GrpcTransportMessage(TransportMessage message, HostInfo host)
        {
            Host      = host;
            Message   = message;
            _envelope = message.Deliver.Envelope;

            Body = message.Deliver.Envelope.Body.ToByteArray();

            ContentType = message.Deliver.Envelope.ContentType;

            SendHeaders = new DictionarySendHeaders();

            foreach (KeyValuePair <string, string> header in message.Deliver.Envelope.Headers)
            {
                SendHeaders.Set(header.Key, header.Value);
            }
        }