Amqp.Framing.Properties.SetCorrelationId C# (CSharp) Method

SetCorrelationId() public method

Sets the correlation identifier. If not null, the object type must be string, Guid, ulong or byte[].
public SetCorrelationId ( object id ) : void
id object The identifier object to set.
return void
        public void SetCorrelationId(object id)
        {
            this.Fields[5] = ValidateIdentifier(id);
        }

Usage Example

Beispiel #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);
            }
        }