Beispiel #1
0
        async Task ISendTransport.Move(ReceiveContext context, IPipe <SendContext> pipe)
        {
            BrokeredMessageContext messageContext;

            if (context.TryGetPayload(out messageContext))
            {
                using (Stream messageBodyStream = context.GetBody())
                {
                    using (var brokeredMessage = new BrokeredMessage(messageBodyStream))
                    {
                        brokeredMessage.ContentType      = context.ContentType.MediaType;
                        brokeredMessage.ForcePersistence = messageContext.ForcePersistence;
                        brokeredMessage.TimeToLive       = messageContext.TimeToLive;
                        brokeredMessage.CorrelationId    = messageContext.CorrelationId;
                        brokeredMessage.MessageId        = messageContext.MessageId;
                        brokeredMessage.Label            = messageContext.Label;
                        brokeredMessage.PartitionKey     = messageContext.PartitionKey;
                        brokeredMessage.ReplyTo          = messageContext.ReplyTo;
                        brokeredMessage.ReplyToSessionId = messageContext.ReplyToSessionId;
                        brokeredMessage.SessionId        = messageContext.SessionId;

                        await _sender.SendAsync(brokeredMessage);

                        _log.DebugFormat("MOVE {0} ({1} to {2})", brokeredMessage.MessageId, context.InputAddress, _sender.Path);
                    }
                }
            }
        }
Beispiel #2
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;
                }
            }
        async Task ISendTransport.Move(ReceiveContext context, IPipe <SendContext> pipe)
        {
            IPipe <ModelContext> modelPipe = Pipe.New <ModelContext>(p =>
            {
                p.UseFilter(_filter);

                p.UseExecuteAsync(async modelContext =>
                {
                    try
                    {
                        IBasicProperties properties;
                        string routingKey = "";

                        RabbitMqBasicConsumeContext basicConsumeContext;
                        if (context.TryGetPayload(out basicConsumeContext))
                        {
                            properties = basicConsumeContext.Properties;
                            routingKey = basicConsumeContext.RoutingKey;
                        }
                        else
                        {
                            properties         = modelContext.Model.CreateBasicProperties();
                            properties.Headers = new Dictionary <string, object>();
                        }

                        var moveContext = new RabbitMqMoveContext(context, properties, _exchange, routingKey ?? "");

                        await pipe.Send(moveContext).ConfigureAwait(false);

                        byte[] body;
                        using (var memoryStream = new MemoryStream())
                        {
                            using (var bodyStream = context.GetBody())
                            {
                                await bodyStream.CopyToAsync(memoryStream).ConfigureAwait(false);
                            }

                            body = memoryStream.ToArray();
                        }

                        var task = modelContext.BasicPublishAsync(_exchange, "", true, properties, body, true);
                        context.AddPendingTask(task);
                    }
                    catch (Exception ex)
                    {
                        if (_log.IsErrorEnabled)
                        {
                            _log.Error("Faulted moving message to error queue: " + _exchange, ex);
                        }

                        throw;
                    }
                });
            });

            await _modelCache.Send(modelPipe, context.CancellationToken).ConfigureAwait(false);
        }
        async Task ISendTransport.Move(ReceiveContext context, IPipe <SendContext> pipe)
        {
            var messageId = GetMessageId(context);

            byte[] body;
            using (var bodyStream = context.GetBody())
            {
                body = await GetMessageBody(bodyStream).ConfigureAwait(false);
            }

            var messageType = "Unknown";
            InMemoryTransportMessage receivedMessage;

            if (context.TryGetPayload(out receivedMessage))
            {
                messageType = receivedMessage.MessageType;
            }

            var transportMessage = new InMemoryTransportMessage(messageId, body, context.ContentType.MediaType, messageType);

            await _exchange.Send(transportMessage).ConfigureAwait(false);
        }
Beispiel #5
0
        async Task ISendTransport.Move(ReceiveContext context, IPipe <SendContext> pipe)
        {
            var messageId = GetMessageId(context);

            byte[] body;
            using (var bodyStream = context.GetBody())
            {
                body = await GetMessageBody(bodyStream).ConfigureAwait(false);
            }

            var messageType = "Unknown";
            InMemoryTransportMessage receivedMessage;

            if (context.TryGetPayload(out receivedMessage))
            {
                messageType = receivedMessage.MessageType;
            }

            var transportMessage = new InMemoryTransportMessage(messageId, body, context.ContentType.MediaType, messageType);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Factory.StartNew(() => DispatchMessage(transportMessage), _supervisor.StoppedToken, TaskCreationOptions.None, _scheduler);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
Beispiel #6
0
 bool PipeContext.TryGetPayload <TPayload>(out TPayload payload)
 {
     return(_context.TryGetPayload(out payload));
 }
Beispiel #7
0
 public bool TryGetPayload <TPayload>(out TPayload payload)
     where TPayload : class
 {
     return(_receiveContext.TryGetPayload(out payload));
 }
        async Task ISendTransport.Move(ReceiveContext context, IPipe <SendContext> pipe)
        {
            IPipe <ModelContext> modelPipe = Pipe.New <ModelContext>(p =>
            {
                p.UseFilter(_filter);

                p.UseExecuteAsync(async modelContext =>
                {
                    Guid?messageId = context.TransportHeaders.Get("MessageId", default(Guid?));

                    try
                    {
                        IBasicProperties properties;

                        RabbitMqBasicConsumeContext basicConsumeContext;
                        if (context.TryGetPayload(out basicConsumeContext))
                        {
                            properties = basicConsumeContext.Properties;
                        }
                        else
                        {
                            properties         = modelContext.Model.CreateBasicProperties();
                            properties.Headers = new Dictionary <string, object>();
                        }

                        var moveContext = new RabbitMqMoveContext(context, properties);

                        await pipe.Send(moveContext).ConfigureAwait(false);

//                        properties.Headers["Content-Type"] = context.ContentType.MediaType;

//                        if (messageId.HasValue)
//                            properties.MessageId = messageId.ToString();

                        byte[] body;
                        using (var memoryStream = new MemoryStream())
                        {
                            using (Stream bodyStream = context.GetBody())
                            {
                                bodyStream.CopyTo(memoryStream);
                            }

                            body = memoryStream.ToArray();
                        }

                        Task task = modelContext.BasicPublishAsync(_sendSettings.ExchangeName, "", true, properties, body);
                        context.AddPendingTask(task);

                        if (_log.IsDebugEnabled)
                        {
                            context.InputAddress.LogMoved(modelContext.ConnectionContext.HostSettings.GetSendAddress(_sendSettings),
                                                          messageId?.ToString() ?? "N/A", "Moved");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (_log.IsErrorEnabled)
                        {
                            _log.Error("Move To Error Queue Fault: " + _sendSettings.ExchangeName, ex);
                        }

                        throw;
                    }
                });
            });

            await _modelCache.Send(modelPipe, context.CancellationToken).ConfigureAwait(false);
        }