protected IMessage ToMessagingMessage(IMessage amqpMessage)
        {
            if (BatchingStrategy.CanDebatch(amqpMessage.Headers))
            {
                var list = new List <object>();
                BatchingStrategy.DeBatch(amqpMessage, fragment =>
                {
                    var convertedObject = MessageConverter.FromMessage(amqpMessage, null);
                    if (convertedObject == null)
                    {
                        throw new MessageConversionException("Message converter returned null");
                    }

                    list.Add(convertedObject);
                });

                return(RabbitMessageBuilder.WithPayload(list).CopyHeaders(amqpMessage.Headers).Build());
            }

            PreprocesMessage(amqpMessage);
            var headers         = amqpMessage.Headers;
            var convertedObject = MessageConverter.FromMessage(amqpMessage, InferredArgumentType);

            if (convertedObject == null)
            {
                throw new MessageConversionException("Message converter returned null");
            }

            var builder = (convertedObject is IMessage) ? RabbitMessageBuilder.FromMessage((IMessage)convertedObject) : RabbitMessageBuilder.WithPayload(convertedObject);
            var message = builder.CopyHeadersIfAbsent(headers).Build();

            return(message);
        }
Example #2
0
        public void BuildMessageWithStandardMessage()
        {
            var result = RabbitMessageBuilder.WithPayload("Response")
                         .SetHeader("foo", "bar")
                         .SetHeader(RabbitMessageHeaders.TYPE, "msg_type")
                         .SetHeader(RabbitMessageHeaders.REPLY_TO, "reply")
                         .Build();
            var session      = new Mock <IModel>();
            var listener     = GetSimpleInstance("Echo", typeof(IMessage <string>));
            var replyMessage = listener.BuildMessage(session.Object, result, null);

            Assert.NotNull(replyMessage);
            Assert.Equal("Response", EncodingUtils.GetDefaultEncoding().GetString(replyMessage.Payload));
            Assert.Equal("msg_type", replyMessage.Headers.Type());
            Assert.Equal("reply", replyMessage.Headers.ReplyTo());
            Assert.Equal("bar", replyMessage.Headers.Get <string>("foo"));
        }
Example #3
0
 public IMessage <string> Echo(IMessage <string> input)
 {
     return((IMessage <string>)RabbitMessageBuilder.WithPayload(input.Payload)
            .SetHeader(RabbitMessageHeaders.TYPE, "reply")
            .Build());
 }
        public override void OnMessage(IMessage amqpMessage, RC.IModel channel)
        {
            PreprocesMessage(amqpMessage);
            var headers         = amqpMessage.Headers;
            var convertedObject = MessageConverter.FromMessage(amqpMessage, InferredArgumentType);

            if (convertedObject == null)
            {
                throw new MessageConversionException("Message converter returned null");
            }

            var builder = (convertedObject is IMessage message1) ? RabbitMessageBuilder.FromMessage(message1) : RabbitMessageBuilder.WithPayload(convertedObject);
            var message = builder.CopyHeadersIfAbsent(headers).Build();

            InvokeHandlerAndProcessResult(amqpMessage, channel, message);
        }