Beispiel #1
0
        public static AmqpMessage BrokerGetMessage(BrokeredMessage brokeredMessage)
        {
            AmqpMessage messageId = null;
            bool        flag      = true;

            if (brokeredMessage.MessageFormat == BrokeredMessageFormat.PassthroughAmqp)
            {
                flag      = false;
                messageId = AmqpMessage.CreateAmqpStreamMessage((BufferListStream)brokeredMessage.BodyStream, true);
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Amqp)
            {
                messageId = AmqpMessage.CreateAmqpStreamMessage(brokeredMessage.RawHeaderStream, brokeredMessage.BodyStream, true);
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.AmqpEventData)
            {
                flag = false;
                BufferListStream bufferListStream = BufferListStream.Create(brokeredMessage.BodyStream, 512, true);
                messageId = AmqpMessage.CreateOutputMessage(bufferListStream, true);
                MessageAnnotations messageAnnotations = messageId.MessageAnnotations;
                messageAnnotations.Map["x-opt-sequence-number"] = brokeredMessage.SequenceNumber;
                Annotations map        = messageAnnotations.Map;
                AmqpSymbol  amqpSymbol = "x-opt-offset";
                long        offset     = brokeredMessage.Offset;
                map[amqpSymbol] = offset.ToString(NumberFormatInfo.InvariantInfo);
                messageAnnotations.Map["x-opt-enqueued-time"] = brokeredMessage.EnqueuedTimeUtc;
                if (!string.IsNullOrEmpty(brokeredMessage.Publisher))
                {
                    messageAnnotations.Map["x-opt-publisher"]     = brokeredMessage.Publisher;
                    messageAnnotations.Map["x-opt-partition-key"] = brokeredMessage.Publisher;
                }
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Sbmp)
            {
                brokeredMessage.SetPropertiesAsModifiedByBroker();
                messageId = MessageConverter.CreateAmqpMessageFromSbmpMessage(brokeredMessage);
                messageId.Properties.MessageId      = brokeredMessage.MessageId;
                messageId.Properties.CorrelationId  = brokeredMessage.CorrelationId;
                messageId.Properties.ContentType    = brokeredMessage.ContentType;
                messageId.Properties.Subject        = brokeredMessage.Label;
                messageId.Properties.To             = brokeredMessage.To;
                messageId.Properties.ReplyTo        = brokeredMessage.ReplyTo;
                messageId.Properties.GroupId        = brokeredMessage.SessionId;
                messageId.Properties.ReplyToGroupId = brokeredMessage.ReplyToSessionId;
            }
            if (flag)
            {
                MessageConverter.UpdateAmqpMessageHeadersAndProperties(messageId, brokeredMessage, true);
            }
            return(messageId);
        }