Java Code Examples for org.apache.qpid.proton.message.impl.MessageImpl#setDeliveryAnnotations()

The following examples show how to use org.apache.qpid.proton.message.impl.MessageImpl#setDeliveryAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDeliveryAnnotations() {
   MessageImpl protonMessage = createProtonMessage();
   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   deliveryAnnotations.getValue().put(Symbol.valueOf(UUID.randomUUID().toString()), "test-1");
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);

   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   DeliveryAnnotations decoded = message.getDeliveryAnnotations();
   assertNotSame(decoded, protonMessage.getDeliveryAnnotations());
   assertDeliveryAnnotationsEquals(protonMessage.getDeliveryAnnotations(), decoded);

   // Update the values
   decoded.getValue().put(Symbol.valueOf(UUID.randomUUID().toString()), "test-2");

   // Check that the message is unaffected.
   assertDeliveryAnnotationsNotEquals(protonMessage.getDeliveryAnnotations(), decoded);
}
 
Example 2
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSendBufferRemoveDeliveryAnnotations() {
   MessageImpl protonMessage = createProtonMessage();
   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   deliveryAnnotations.getValue().put(Symbol.valueOf("testGetSendBufferRemoveDeliveryAnnotations"), "X");
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   ReadableBuffer buffer = message.getSendBuffer(1);
   assertNotNull(buffer);

   AMQPStandardMessage copy = new AMQPStandardMessage(0, buffer, null, null);

   MessageImpl copyProtonMessage = copy.getProtonMessage();
   assertProtonMessageNotEquals(message.getProtonMessage(), copyProtonMessage);
   assertNull(copyProtonMessage.getDeliveryAnnotations());
}
 
Example 3
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSendBufferAddsDeliveryCountOnlyToSendMessageAndTrimsDeliveryAnnotations() {
   MessageImpl protonMessage = createProtonMessage();
   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   deliveryAnnotations.getValue().put(Symbol.valueOf("testGetSendBufferRemoveDeliveryAnnotations"), "X");
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   ReadableBuffer buffer = message.getSendBuffer(7);
   assertNotNull(buffer);
   message.reencode(); // Ensures Header is current if accidentally updated

   AMQPStandardMessage copy = new AMQPStandardMessage(0, buffer, null, null);

   MessageImpl originalsProtonMessage = message.getProtonMessage();
   MessageImpl copyProtonMessage = copy.getProtonMessage();
   assertProtonMessageNotEquals(originalsProtonMessage, copyProtonMessage);

   assertNull(originalsProtonMessage.getHeader().getDeliveryCount());
   assertEquals(6, copyProtonMessage.getHeader().getDeliveryCount().intValue());
   assertNull(copyProtonMessage.getDeliveryAnnotations());
}
 
Example 4
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyMessageDoesNotRemovesMessageAnnotations() {
   MessageImpl protonMessage = createProtonMessage();
   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   deliveryAnnotations.getValue().put(Symbol.valueOf("testCopyMessageRemovesMessageAnnotations"), "1");
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);

   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);
   message.setMessageID(127);
   AMQPStandardMessage copy = (AMQPStandardMessage) message.copy();

   assertEquals(message.getMessageID(), copy.getMessageID());
   assertProtonMessageEquals(message.getProtonMessage(), copy.getProtonMessage());
   assertNotNull(copy.getDeliveryAnnotations());
}
 
Example 5
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSendBufferWithoutDeliveryAnnotations() {
   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   Header header = new Header();
   header.setDeliveryCount(new UnsignedInteger(1));
   protonMessage.setHeader(header);
   Properties properties = new Properties();
   properties.setTo("someNiceLocal");
   protonMessage.setProperties(properties);
   protonMessage.setBody(new AmqpValue("Sample payload"));

   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   final String annotationKey = "annotationKey";
   final String annotationValue = "annotationValue";
   deliveryAnnotations.getValue().put(Symbol.getSymbol(annotationKey), annotationValue);
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);

   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   ReadableBuffer sendBuffer = decoded.getSendBuffer(1);
   assertEquals(decoded.getEncodeSize(), sendBuffer.capacity());
   AMQPStandardMessage msgFromSendBuffer = new AMQPStandardMessage(0, sendBuffer, null, null);
   assertEquals("someNiceLocal", msgFromSendBuffer.getAddress());
   assertNull(msgFromSendBuffer.getDeliveryAnnotations());

   // again with higher deliveryCount
   ReadableBuffer sendBuffer2 = decoded.getSendBuffer(5);
   assertEquals(decoded.getEncodeSize(), sendBuffer2.capacity());
   AMQPStandardMessage msgFromSendBuffer2 = new AMQPStandardMessage(0, sendBuffer2, null, null);
   assertEquals("someNiceLocal", msgFromSendBuffer2.getAddress());
   assertNull(msgFromSendBuffer2.getDeliveryAnnotations());
}