示例#1
0
        public void SBMessageWithNoTTLResultsInEmptyAmpqTTL()
        {
            var sbMessage = new ServiceBusMessage();

            var amqpMessage = AmqpMessageConverter.SBMessageToAmqpMessage(sbMessage);

            Assert.Null(amqpMessage.Header.Ttl);
        }
        void SB_message_with_no_TTL_results_in_empty_Ampq_TTL()
        {
            var sbMessage = new Message();

            var amqpMessage = AmqpMessageConverter.SBMessageToAmqpMessage(sbMessage);

            Assert.Null(amqpMessage.Header.Ttl);
        }
        void Convert_SB_message_to_Amqp_message_and_back()
        {
            var messageBody     = Encoding.UTF8.GetBytes("hello");
            var messageId       = Guid.NewGuid().ToString();
            var partitionKey    = Guid.NewGuid().ToString();
            var viaPartitionKey = Guid.NewGuid().ToString();
            var sessionId       = Guid.NewGuid().ToString();
            var correlationId   = Guid.NewGuid().ToString();
            var label           = Guid.NewGuid().ToString();
            var to               = Guid.NewGuid().ToString();
            var contentType      = Guid.NewGuid().ToString();
            var replyTo          = Guid.NewGuid().ToString();
            var replyToSessionId = Guid.NewGuid().ToString();
            var publisher        = Guid.NewGuid().ToString();
            var timeToLive       = TimeSpan.FromDays(5);

            var sbMessage = new Message(messageBody)
            {
                MessageId       = messageId,
                PartitionKey    = partitionKey,
                ViaPartitionKey = viaPartitionKey,
                SessionId       = sessionId,
                CorrelationId   = correlationId,
                Label           = label,
                To               = to,
                ContentType      = contentType,
                ReplyTo          = replyTo,
                ReplyToSessionId = replyToSessionId,
                TimeToLive       = timeToLive
            };

            sbMessage.UserProperties.Add("UserProperty", "SomeUserProperty");

            var amqpMessage        = AmqpMessageConverter.SBMessageToAmqpMessage(sbMessage);
            var convertedSbMessage = AmqpMessageConverter.AmqpMessageToSBMessage(amqpMessage);

            Assert.Equal("SomeUserProperty", convertedSbMessage.UserProperties["UserProperty"]);
            Assert.Equal(messageBody, convertedSbMessage.Body);
            Assert.Equal(messageId, convertedSbMessage.MessageId);
            Assert.Equal(partitionKey, convertedSbMessage.PartitionKey);
            Assert.Equal(viaPartitionKey, convertedSbMessage.ViaPartitionKey);
            Assert.Equal(sessionId, convertedSbMessage.SessionId);
            Assert.Equal(correlationId, convertedSbMessage.CorrelationId);
            Assert.Equal(label, convertedSbMessage.Label);
            Assert.Equal(to, convertedSbMessage.To);
            Assert.Equal(contentType, convertedSbMessage.ContentType);
            Assert.Equal(replyTo, convertedSbMessage.ReplyTo);
            Assert.Equal(replyToSessionId, convertedSbMessage.ReplyToSessionId);
            Assert.Equal(timeToLive, convertedSbMessage.TimeToLive);
        }
示例#4
0
        public void ConvertSBMessageToAmqpMessageAndBack()
        {
            var messageBody     = Encoding.UTF8.GetBytes("hello");
            var messageId       = Guid.NewGuid().ToString();
            var partitionKey    = Guid.NewGuid().ToString();
            var viaPartitionKey = Guid.NewGuid().ToString();
            var sessionId       = partitionKey;
            var correlationId   = Guid.NewGuid().ToString();
            var label           = Guid.NewGuid().ToString();
            var to               = Guid.NewGuid().ToString();
            var contentType      = Guid.NewGuid().ToString();
            var replyTo          = Guid.NewGuid().ToString();
            var replyToSessionId = Guid.NewGuid().ToString();
            var timeToLive       = TimeSpan.FromDays(5);

            var sbMessage = new ServiceBusMessage(messageBody)
            {
                MessageId               = messageId,
                PartitionKey            = partitionKey,
                TransactionPartitionKey = viaPartitionKey,
                SessionId               = sessionId,
                CorrelationId           = correlationId,
                Subject          = label,
                To               = to,
                ContentType      = contentType,
                ReplyTo          = replyTo,
                ReplyToSessionId = replyToSessionId,
                TimeToLive       = timeToLive,
            };

            sbMessage.ApplicationProperties.Add("UserProperty", "SomeUserProperty");

            var amqpMessage        = AmqpMessageConverter.SBMessageToAmqpMessage(sbMessage);
            var convertedSbMessage = AmqpMessageConverter.AmqpMessageToSBMessage(amqpMessage);

            Assert.AreEqual("SomeUserProperty", convertedSbMessage.ApplicationProperties["UserProperty"]);
            Assert.AreEqual(messageBody, convertedSbMessage.Body.ToArray());
            Assert.AreEqual(messageId, convertedSbMessage.MessageId);
            Assert.AreEqual(partitionKey, convertedSbMessage.PartitionKey);
            Assert.AreEqual(viaPartitionKey, convertedSbMessage.TransactionPartitionKey);
            Assert.AreEqual(sessionId, convertedSbMessage.SessionId);
            Assert.AreEqual(correlationId, convertedSbMessage.CorrelationId);
            Assert.AreEqual(label, convertedSbMessage.Subject);
            Assert.AreEqual(to, convertedSbMessage.To);
            Assert.AreEqual(contentType, convertedSbMessage.ContentType);
            Assert.AreEqual(replyTo, convertedSbMessage.ReplyTo);
            Assert.AreEqual(replyToSessionId, convertedSbMessage.ReplyToSessionId);
            Assert.AreEqual(timeToLive, convertedSbMessage.TimeToLive);
        }
示例#5
0
        void Convert_SB_message_to_Amqp_message_and_back()
        {
            var messageBody      = Encoding.UTF8.GetBytes("hello");
            var messageId        = Guid.NewGuid().ToString();
            var partitionKey     = Guid.NewGuid().ToString();
            var sessionId        = Guid.NewGuid().ToString();
            var correlationId    = Guid.NewGuid().ToString();
            var label            = Guid.NewGuid().ToString();
            var to               = Guid.NewGuid().ToString();
            var contentType      = Guid.NewGuid().ToString();
            var replyTo          = Guid.NewGuid().ToString();
            var replyToSessionId = Guid.NewGuid().ToString();
            var publisher        = Guid.NewGuid().ToString();
            var deadLetterSource = Guid.NewGuid().ToString();

            var sbMessage = new Message(messageBody)
            {
                MessageId        = messageId,
                PartitionKey     = partitionKey,
                SessionId        = sessionId,
                CorrelationId    = correlationId,
                Label            = label,
                To               = to,
                ContentType      = contentType,
                ReplyTo          = replyTo,
                ReplyToSessionId = replyToSessionId,
                Publisher        = publisher,
                DeadLetterSource = deadLetterSource,
            };

            sbMessage.UserProperties.Add("UserProperty", "SomeUserProperty");

            var amqpMessage = AmqpMessageConverter.SBMessageToAmqpMessage(sbMessage);
            var convertedBrokeredMessage = AmqpMessageConverter.AmqpMessageToSBMessage(amqpMessage);

            Assert.Equal("SomeUserProperty", convertedBrokeredMessage.UserProperties["UserProperty"]);
            Assert.Equal(messageBody, convertedBrokeredMessage.Body);
            Assert.Equal(messageId, convertedBrokeredMessage.MessageId);
            Assert.Equal(partitionKey, convertedBrokeredMessage.PartitionKey);
            Assert.Equal(sessionId, convertedBrokeredMessage.SessionId);
            Assert.Equal(correlationId, convertedBrokeredMessage.CorrelationId);
            Assert.Equal(label, convertedBrokeredMessage.Label);
            Assert.Equal(to, convertedBrokeredMessage.To);
            Assert.Equal(contentType, convertedBrokeredMessage.ContentType);
            Assert.Equal(replyTo, convertedBrokeredMessage.ReplyTo);
            Assert.Equal(replyToSessionId, convertedBrokeredMessage.ReplyToSessionId);
            Assert.Equal(publisher, convertedBrokeredMessage.Publisher);
            Assert.Equal(deadLetterSource, convertedBrokeredMessage.DeadLetterSource);
        }
        async Task <long> OnScheduleMessageAsync(Message message)
        {
            // TODO: Ensure System.Transactions.Transaction.Current is null. Transactions are not supported by 1.0.0 version of dotnet core.
            using (AmqpMessage amqpMessage = AmqpMessageConverter.SBMessageToAmqpMessage(message))
            {
                var request = AmqpRequestMessage.CreateRequest(
                    ManagementConstants.Operations.ScheduleMessageOperation,
                    this.OperationTimeout,
                    null);

                ArraySegment <byte>[] payload = amqpMessage.GetPayload();
                BufferListStream      buffer  = new BufferListStream(payload);
                ArraySegment <byte>   value   = buffer.ReadBytes((int)buffer.Length);

                var entry = new AmqpMap();
                {
                    entry[ManagementConstants.Properties.Message]   = value;
                    entry[ManagementConstants.Properties.MessageId] = message.MessageId;

                    if (!string.IsNullOrWhiteSpace(message.SessionId))
                    {
                        entry[ManagementConstants.Properties.SessionId] = message.SessionId;
                    }

                    if (!string.IsNullOrWhiteSpace(message.PartitionKey))
                    {
                        entry[ManagementConstants.Properties.PartitionKey] = message.PartitionKey;
                    }
                }

                request.Map[ManagementConstants.Properties.Messages] = new List <AmqpMap> {
                    entry
                };

                IEnumerable <long> sequenceNumbers = null;
                var response = await this.ExecuteRequestResponseAsync(request).ConfigureAwait(false);

                if (response.StatusCode == AmqpResponseStatusCode.OK)
                {
                    sequenceNumbers = response.GetValue <long[]>(ManagementConstants.Properties.SequenceNumbers);
                }
                else
                {
                    response.ToMessagingContractException();
                }

                return(sequenceNumbers?.FirstOrDefault() ?? 0);
            }
        }