private Message FailureMessage(HeaderResult <string> topic, HeaderResult <Guid> messageId)
        {
            var header = new MessageHeader(
                messageId.Success ? messageId.Result : Guid.Empty,
                topic.Success ? topic.Result : string.Empty,
                MessageType.MT_UNACCEPTABLE);
            var message = new Message(header, new MessageBody(string.Empty));

            return(message);
        }
Beispiel #2
0
        public Message CreateMessage(ConsumeResult <Null, string> consumeResult)
        {
            var headers = consumeResult.Message.Headers;
            var topic   = HeaderResult <string> .Empty();

            var messageId = HeaderResult <Guid> .Empty();

            var timeStamp = HeaderResult <DateTime> .Empty();

            var messageType = HeaderResult <MessageType> .Empty();

            var correlationId = HeaderResult <Guid> .Empty();

            Message message;

            try
            {
                topic         = ReadTopic(consumeResult.Topic);
                messageId     = ReadMessageId(consumeResult.Message.Headers);
                timeStamp     = ReadTimeStamp(consumeResult.Message.Headers);
                messageType   = ReadMessageType(consumeResult.Message.Headers);
                correlationId = ReadCorrelationId(consumeResult.Message.Headers);

                if (false == (topic.Success && messageId.Success && messageType.Success && timeStamp.Success))
                {
                    message = FailureMessage(topic, messageId);
                }
                else
                {
                    var messageHeader = timeStamp.Success
                        ? new MessageHeader(messageId.Result, topic.Result, messageType.Result, timeStamp.Result)
                        : new MessageHeader(messageId.Result, topic.Result, messageType.Result);

                    if (correlationId.Success)
                    {
                        messageHeader.CorrelationId = correlationId.Result;
                    }

                    message = new Message(messageHeader, new MessageBody(consumeResult.Message.Value));

                    headers.Each(header => message.Header.Bag.Add(header.Key, ParseHeaderValue(header)));
                }
            }
            catch (Exception e)
            {
                s_logger.Value.WarnException("Failed to create message from amqp message", e);
                message = FailureMessage(topic, messageId);
            }

            return(message);
        }
        public Message CreateMessage(ConsumeResult <string, string> consumeResult)
        {
            var headers = consumeResult.Message.Headers;
            var topic   = HeaderResult <string> .Empty();

            var messageId = HeaderResult <Guid> .Empty();

            var timeStamp = HeaderResult <DateTime> .Empty();

            var messageType = HeaderResult <MessageType> .Empty();

            var correlationId = HeaderResult <Guid> .Empty();

            var partitionKey = HeaderResult <string> .Empty();

            Message message;

            try
            {
                topic         = ReadTopic(consumeResult.Topic);
                messageId     = ReadMessageId(consumeResult.Message.Headers);
                timeStamp     = ReadTimeStamp(consumeResult.Message.Headers);
                messageType   = ReadMessageType(consumeResult.Message.Headers);
                correlationId = ReadCorrelationId(consumeResult.Message.Headers);
                partitionKey  = ReadPartitionKey(consumeResult.Message.Headers);


                if (false == (topic.Success && messageId.Success && messageType.Success && timeStamp.Success))
                {
                    message = FailureMessage(topic, messageId);
                }
                else
                {
                    var messageHeader = timeStamp.Success
                        ? new MessageHeader(messageId.Result, topic.Result, messageType.Result, timeStamp.Result)
                        : new MessageHeader(messageId.Result, topic.Result, messageType.Result);

                    if (correlationId.Success)
                    {
                        messageHeader.CorrelationId = correlationId.Result;
                    }

                    if (partitionKey.Success)
                    {
                        messageHeader.PartitionKey = partitionKey.Result;
                    }

                    message = new Message(messageHeader, new MessageBody(consumeResult.Message.Value));

                    headers.Each(header => message.Header.Bag.Add(header.Key, ParseHeaderValue(header)));

                    if (!message.Header.Bag.ContainsKey(HeaderNames.PARTITION_OFFSET))
                    {
                        message.Header.Bag.Add(HeaderNames.PARTITION_OFFSET, consumeResult.TopicPartitionOffset);
                    }
                }
            }
            catch (Exception e)
            {
                s_logger.LogWarning(e, "Failed to create message from amqp message");
                message = FailureMessage(topic, messageId);
            }

            return(message);
        }