Exemple #1
0
            public ServiceBusMoveContext(ReceiveContext context)
            {
                _context    = context;
                _serializer = new CopyBodySerializer(context);

                BrokeredMessageContext messageContext;

                if (!context.TryGetPayload(out messageContext))
                {
                    throw new ArgumentException("The context must be a service bus receive context", nameof(context));
                }

                _messageBodyStream = context.GetBody();
                _brokeredMessage   = 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
                };

                Headers = new DictionarySendHeaders(_brokeredMessage.Properties);

                foreach (KeyValuePair <string, object> property in messageContext.Properties)
                {
                    _brokeredMessage.Properties[property.Key] = property.Value;
                }
            }
Exemple #2
0
        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));
        }
        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);
            }
        }