Beispiel #1
0
        static async Task <ISendEndpoint> GetFaultEndpoint(ReceiveContext context, ConsumeContext consumeContext, Guid?requestId)
        {
            Task ConsumeTask(Task task)
            {
                context.AddReceiveTask(task);
                return(task);
            }

            var destinationAddress = consumeContext?.FaultAddress ?? consumeContext?.ResponseAddress;

            if (destinationAddress != null)
            {
                var sendEndpoint = await context.SendEndpointProvider.GetSendEndpoint(destinationAddress).ConfigureAwait(false);

                return(new ConsumeSendEndpoint(sendEndpoint, consumeContext, ConsumeTask, requestId));
            }

            var publishSendEndpoint = await context.PublishEndpointProvider.GetPublishSendEndpoint <ReceiveFault>().ConfigureAwait(false);

            if (consumeContext != null)
            {
                return(new ConsumeSendEndpoint(publishSendEndpoint, consumeContext, ConsumeTask, requestId));
            }

            return(publishSendEndpoint);
        }
Beispiel #2
0
        protected async Task Move(ReceiveContext context, Action <SendMessageRequest, SendHeaders> preSend)
        {
            if (!context.TryGetPayload(out ClientContext clientContext))
            {
                throw new ArgumentException("The ReceiveContext must contain a ClientContext (from Amazon SQS)", nameof(context));
            }

            await _topologyFilter.Send(clientContext, Pipe.Empty <ClientContext>()).ConfigureAwait(false);

            var message = clientContext.CreateSendRequest(_destination, context.GetBody());

            if (context.TryGetPayload(out AmazonSqsMessageContext messageContext))
            {
                foreach (var key in messageContext.Attributes.Keys)
                {
                    if (key.StartsWith("MT-"))
                    {
                        continue;
                    }

                    message.MessageAttributes[key] = messageContext.Attributes[key];
                }
            }

            SendHeaders headers = new AmazonSqsHeaderAdapter(message.MessageAttributes);

            preSend(message, headers);

            var task = clientContext.SendMessage(message, context.CancellationToken);

            context.AddReceiveTask(task);
        }
        protected async Task Move(ReceiveContext context, Action <IMessage, SendHeaders> preSend)
        {
            if (!context.TryGetPayload(out SessionContext sessionContext))
            {
                throw new ArgumentException("The ReceiveContext must contain a BrokeredMessageContext (from Azure Service Bus)", nameof(context));
            }

            await _topologyFilter.Send(sessionContext, Pipe.Empty <SessionContext>()).ConfigureAwait(false);

            var queue = await sessionContext.GetQueue(_destination).ConfigureAwait(false);

            var producer = await sessionContext.CreateMessageProducer(queue).ConfigureAwait(false);

            byte[] body = context.GetBody();

            var message = producer.CreateBytesMessage();

            if (context.TryGetPayload(out ActiveMqMessageContext messageContext))
            {
                foreach (string key in messageContext.Properties.Keys)
                {
                    message.Properties[key] = messageContext.Properties[key];
                }
            }

            SendHeaders headers = new ActiveMqHeaderAdapter(message.Properties);

            headers.SetHostHeaders();

            preSend(message, headers);

            message.Content = body;

            var task      = Task.Run(() => producer.Send(message));
            var closeTask = task.ContinueWith(_ =>
            {
                producer.Close();
                producer.Dispose();
            });

            context.AddReceiveTask(task);
            context.AddReceiveTask(closeTask);
        }
Beispiel #4
0
        protected async Task Move(ReceiveContext context, Action <SendMessageBatchRequestEntry, IDictionary <string, MessageAttributeValue> > preSend)
        {
            if (!context.TryGetPayload(out ClientContext clientContext))
            {
                throw new ArgumentException("The ReceiveContext must contain a ClientContext (from Amazon SQS)", nameof(context));
            }

            await _topologyFilter.Send(clientContext, Pipe.Empty <ClientContext>()).ConfigureAwait(false);

            var message = new SendMessageBatchRequestEntry("", Encoding.UTF8.GetString(context.GetBody()));

            CopyReceivedMessageHeaders(context, message.MessageAttributes);

            preSend(message, message.MessageAttributes);

            var task = clientContext.SendMessage(_destination, message, context.CancellationToken);

            context.AddReceiveTask(task);
        }
        protected async Task Move(ReceiveContext context, Action <IBasicProperties, SendHeaders> preSend)
        {
            if (!context.TryGetPayload(out ModelContext modelContext))
            {
                throw new ArgumentException("The ReceiveContext must contain a BrokeredMessageContext (from Azure Service Bus)", nameof(context));
            }

            await _topologyFilter.Send(modelContext, Pipe.Empty <ModelContext>()).ConfigureAwait(false);

            IBasicProperties properties;
            string           routingKey = "";

            byte[] body;

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

                body = context.GetBody();
            }

            SendHeaders headers = new RabbitMqSendHeaders(properties);

            headers.SetHostHeaders();

            preSend(properties, headers);

            var task = modelContext.BasicPublishAsync(_exchange, routingKey, true, properties, body, true);

            context.AddReceiveTask(task);
        }
Beispiel #6
0
        protected async Task Move(ReceiveContext context, Action <SendMessageBatchRequestEntry, IDictionary <string, MessageAttributeValue> > preSend)
        {
            if (!context.TryGetPayload(out ClientContext clientContext))
            {
                throw new ArgumentException("The ReceiveContext must contain a ClientContext (from Amazon SQS)", nameof(context));
            }

            await _topologyFilter.Send(clientContext, Pipe.Empty <ClientContext>()).ConfigureAwait(false);

            var message = new SendMessageBatchRequestEntry("", Encoding.UTF8.GetString(context.GetBody()));

            if (context.TryGetPayload(out AmazonSqsMessageContext receiveContext))
            {
                if (_isFifo)
                {
                    if (receiveContext.TransportMessage.Attributes.TryGetValue(MessageSystemAttributeName.MessageGroupId, out var messageGroupId) &&
                        !string.IsNullOrWhiteSpace(messageGroupId))
                    {
                        message.MessageGroupId = messageGroupId;
                    }
                    if (receiveContext.TransportMessage.Attributes.TryGetValue(MessageSystemAttributeName.MessageDeduplicationId,
                                                                               out var messageDeduplicationId) &&
                        !string.IsNullOrWhiteSpace(messageDeduplicationId))
                    {
                        message.MessageDeduplicationId = messageDeduplicationId;
                    }
                }

                CopyReceivedMessageHeaders(receiveContext, message.MessageAttributes);
            }

            preSend(message, message.MessageAttributes);

            var task = clientContext.SendMessage(_destination, message, context.CancellationToken);

            context.AddReceiveTask(task);
        }