public void AmqpMessageReceiveResendTest() { var message = AmqpMessage.Create(new AmqpValue { Value = "Hello, AMQP!" }); message.MessageAnnotations.Map["key"] = "old"; // send the message and receive it on remote side var payload = message.GetPayload(); var streamMessage = AmqpMessage.CreateAmqpStreamMessage(new BufferListStream(payload)); //new OutputMessage for resending with modified sections var stream = BufferListStream.Create(streamMessage.ToStream(), AmqpConstants.SegmentSize, streamMessage.Settled); stream.Seek(0, System.IO.SeekOrigin.Begin); var outMessage = AmqpMessage.CreateOutputMessage(stream, false); outMessage.Settled = streamMessage.Settled; //explicitly assign outMessage.Header.Priority = 99; outMessage.DeliveryAnnotations.Map["key"] = "da-update"; outMessage.MessageAnnotations.Map["key"] = "update"; // send var payload2 = outMessage.GetPayload(); var value = (string)outMessage.MessageAnnotations.Map["key"]; Assert.Equal("update", value); // receive var streamMessage2 = AmqpMessage.CreateAmqpStreamMessage(new BufferListStream(payload2)); Assert.Equal(99, streamMessage2.Header.Priority.Value); value = (string)outMessage.DeliveryAnnotations.Map["key"]; Assert.Equal("da-update", value); value = (string)outMessage.MessageAnnotations.Map["key"]; Assert.Equal("update", value); }
public void AmqpMessageSerializationTest() { // empty message AmqpMessage message = AmqpMessage.Create(); AddSection(message, SectionFlag.Properties); RunSerializationTest(message); // data message message = AmqpMessage.Create(new Data() { Value = new ArraySegment <byte>(new byte[60]) }); RunSerializationTest(message); message = AmqpMessage.Create(new Data[] { new Data() { Value = new ArraySegment <byte>(new byte[60]) }, new Data() { Value = new ArraySegment <byte>(new byte[44]) } }); AddSection(message, SectionFlag.Header | SectionFlag.ApplicationProperties); RunSerializationTest(message); // value message message = AmqpMessage.Create(new AmqpValue() { Value = new AmqpSymbol("symbol value") }); AddSection(message, SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.ApplicationProperties); RunSerializationTest(message); // sequence message message = AmqpMessage.Create(new AmqpSequence[] { new AmqpSequence(new List <object>() { "string1", 1234 }), new AmqpSequence(new List <object>() { DateTime.Parse("2012-01-01 12:00:00").ToUniversalTime() }) }); AddSection(message, SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties | SectionFlag.Footer); RunSerializationTest(message); // data message - binary message = AmqpUtils.CreateMessage(new byte[888]); AddSection(message, SectionFlag.DeliveryAnnotations | SectionFlag.ApplicationProperties | SectionFlag.Footer); RunSerializationTest(message); // body stream message message = AmqpMessage.Create(new MemoryStream(new byte[679]), true); AddSection(message, SectionFlag.Header | SectionFlag.MessageAnnotations | SectionFlag.Footer); RunSerializationTest(message); // the following simulates a message's round trip from client to broker to client // message -serialize-> buffers -> input stream message -> output stream message -deserialize> message message = AmqpMessage.Create(new AmqpValue() { Value = new AmqpSymbol("symbol value") }); AddSection(message, SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties); // serialize - send the message on client side ArraySegment <byte>[] buffers = ReadMessagePayLoad(message, 71); // input stream message - received on broker side AmqpMessage message2 = AmqpMessage.CreateAmqpStreamMessage(new BufferListStream(buffers)); // output stream message - send out on broker side message2 = AmqpMessage.CreateOutputMessage((BufferListStream)message2.ToStream(), true); AddSection(message2, SectionFlag.Header | SectionFlag.DeliveryAnnotations); message2.MessageAnnotations.Map["delivery-count"] = 5; // input stream message - received on client side buffers = ReadMessagePayLoad(message2, 71); message2 = AmqpMessage.CreateAmqpStreamMessage(new BufferListStream(buffers)); // update the original message to match the updated message AddSection(message, SectionFlag.Header | SectionFlag.DeliveryAnnotations); message.MessageAnnotations.Map["delivery-count"] = 5; ValidateMessage(message, message2); }