Beispiel #1
0
        protected 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);
        }
        public Message CreateMessage(Amazon.SQS.Model.Message sqsMessage)
        {
            var topic = HeaderResult <string> .Empty();

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

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

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

            var handledCount = HeaderResult <int> .Empty();

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

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

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

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


            Message message;

            try
            {
                topic         = ReadTopic(sqsMessage);
                messageId     = ReadMessageId(sqsMessage);
                contentType   = ReadContentType(sqsMessage);
                correlationId = ReadCorrelationid(sqsMessage);
                handledCount  = ReadHandledCount(sqsMessage);
                messageType   = ReadMessageType(sqsMessage);
                timeStamp     = ReadTimestamp(sqsMessage);
                replyTo       = ReadReplyTo(sqsMessage);
                receiptHandle = ReadReceiptHandle(sqsMessage);

                if (false == (topic.Success && messageId.Success && contentType.Success && correlationId.Success &&
                              handledCount.Success && messageType.Success && timeStamp.Success &&
                              receiptHandle.Success))
                {
                    return(FailureMessage(topic, messageId));
                }
                else
                {
                    var messageHeader = timeStamp.Success
                        ? new MessageHeader(messageId.Result, topic.Result, messageType.Result, timeStamp.Result, handledCount.Result, 0)
                        : new MessageHeader(messageId.Result, topic.Result, messageType.Result);

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

                    if (replyTo.Success)
                    {
                        messageHeader.ReplyTo = replyTo.Result;
                    }

                    if (contentType.Success)
                    {
                        messageHeader.ContentType = contentType.Result;
                    }

                    message = new Message(messageHeader, new MessageBody(sqsMessage.Body));

                    //deserialize the bag
                    var bag = ReadMessageBag(sqsMessage);
                    foreach (var key in bag.Keys)
                    {
                        message.Header.Bag.Add(key, bag[key]);
                    }


                    if (receiptHandle.Success)
                    {
                        message.Header.Bag.Add("ReceiptHandle", ((Amazon.SQS.Model.Message)sqsMessage).ReceiptHandle);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Value.WarnException("Failed to create message from amqp message", e);
                message = FailureMessage(topic, messageId);
            }


            return(message);
        }
        public Message CreateMessage(Amazon.SQS.Model.Message sqsMessage)
        {
            var topic = HeaderResult <string> .Empty();

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

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

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

            var handledCount = HeaderResult <int> .Empty();

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

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

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

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

            Message message;

            try
            {
                _messageAttributes = ReadMessageAttributes(sqsMessage);

                topic         = ReadTopic();
                messageId     = ReadMessageId();
                contentType   = ReadContentType();
                correlationId = ReadCorrelationId();
                handledCount  = ReadHandledCount();
                messageType   = ReadMessageType();
                timeStamp     = ReadTimestamp();
                replyTo       = ReadReplyTo();
                receiptHandle = ReadReceiptHandle(sqsMessage);

                var messageHeader = timeStamp.Success
                    ? new MessageHeader(messageId.Result, topic.Result, messageType.Result, timeStamp.Result, handledCount.Result, 0)
                    : new MessageHeader(messageId.Result, topic.Result, messageType.Result);

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

                if (replyTo.Success)
                {
                    messageHeader.ReplyTo = replyTo.Result;
                }

                if (contentType.Success)
                {
                    messageHeader.ContentType = contentType.Result;
                }

                message = new Message(messageHeader, ReadMessageBody(sqsMessage));

                //deserialize the bag
                var bag = ReadMessageBag();
                foreach (var key in bag.Keys)
                {
                    message.Header.Bag.Add(key, bag[key]);
                }

                if (receiptHandle.Success)
                {
                    message.Header.Bag.Add("ReceiptHandle", ((Amazon.SQS.Model.Message)sqsMessage).ReceiptHandle);
                }
            }
            catch (Exception e)
            {
                s_logger.LogWarning(e, "Failed to create message from Aws Sqs message");
                message = FailureMessage(topic, messageId);
            }


            return(message);
        }