The Properties class defines the Immutable properties of the Message.
상속: Amqp.Types.DescribedList
예제 #1
0
        public void TestMethod_MessageId()
        {
            string testName = "MessageId";
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);
            object[] idList = new object[] { null, "string-id", 20000UL, Guid.NewGuid(), Encoding.UTF8.GetBytes("binary-id") };

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
            for (int i = 0; i < idList.Length; ++i)
            {
                Message message = new Message() { Properties = new Properties() };
                message.Properties.SetMessageId(idList[i]);
                message.Properties.SetCorrelationId(idList[(i + 2) % idList.Length]);
                sender.Send(message, null, null);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
            for (int i = 0; i < idList.Length; ++i)
            {
                Message message = receiver.Receive();
                receiver.Accept(message);
                Assert.AreEqual(idList[i], message.Properties.GetMessageId());
                Assert.AreEqual(idList[(i + 2) % idList.Length], message.Properties.GetCorrelationId());
            }

            connection.Close();

            // invalid types
            Properties prop = new Properties();
            try
            {
                prop.SetMessageId(0);
                Assert.IsTrue(false, "not a valid identifier type");
            }
            catch (AmqpException ae)
            {
                Assert.AreEqual(ErrorCode.NotAllowed, (string)ae.Error.Condition);
            }

            try
            {
                prop.SetCorrelationId(new Symbol("symbol"));
                Assert.IsTrue(false, "not a valid identifier type");
            }
            catch (AmqpException ae)
            {
                Assert.AreEqual(ErrorCode.NotAllowed, (string)ae.Error.Condition);
            }
        }
예제 #2
0
        public void SendEvent(string linkName, byte[] content)
        {
            var channel = this.channels[linkName];

            var messageProperties = new Properties()
            {
                GroupId = string.Format("send-{0}-p{1}", channel.Name.ToLower(), channel.PartitionId)
            };

            var message = new Amqp.Message()
            {
                BodySection = new Data() { Binary = content },
                Properties = messageProperties,
                MessageAnnotations = new MessageAnnotations()
            };

            message.MessageAnnotations[new Symbol("x-opt-partition-key")] = "pk:" + channel.PartitionId;

            channel.Link.Send(message);
        }