org.apache.qpid.proton.amqp.messaging.Properties Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Properties. 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 testSetReplyToFromMessageWithPropertiesCanClear() {
   final String REPLY_TO = "address-1";

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setProperties(new Properties());
   protonMessage.setReplyTo(REPLY_TO);
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);
   assertEquals(REPLY_TO, decoded.getReplyTo().toString());

   decoded.setReplyTo(null);
   decoded.reencode();

   assertEquals(null, decoded.getReplyTo());
   assertEquals(null, decoded.getProperties().getReplyTo());
}
 
Example #2
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetExpirationToClearUpdatesPropertiesWhenPresent() {
   final Date expirationTime = new Date(System.currentTimeMillis());

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setProperties(new Properties());
   protonMessage.setExpiryTime(expirationTime.getTime());
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertEquals(expirationTime.getTime(), decoded.getExpiration());
   decoded.setExpiration(-1);
   assertEquals(0, decoded.getExpiration());

   decoded.reencode();
   assertEquals(0, decoded.getExpiration());
   assertNull(decoded.getProperties().getAbsoluteExpiryTime());
}
 
Example #3
Source File: AmqpSendReceiveInterceptorTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private boolean checkMessageProperties(AMQPMessage message, Map<String, Object> expectedProperties) {
   assertNotNull(message);
   assertNotNull(server.getNodeID());

   assertNotNull(message.getConnectionID());
   assertEquals(message.getAddress(), expectedProperties.get(ADDRESS));
   assertEquals(message.isDurable(), expectedProperties.get(DURABLE));

   Properties props = message.getProperties();
   assertEquals(props.getCorrelationId(), expectedProperties.get(CORRELATION_ID));
   assertEquals(props.getReplyTo(), expectedProperties.get(REPLY_TO));
   assertEquals(props.getMessageId(), expectedProperties.get(MESSAGE_ID));

   Header header = message.getHeader();
   assertEquals(header.getDurable(), expectedProperties.get(DURABLE));
   assertEquals(header.getTtl().toString(), expectedProperties.get(TIME_TO_LIVE).toString());
   assertEquals(header.getPriority().toString(), expectedProperties.get(PRIORITY).toString());
   return true;
}
 
Example #4
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetTimestampOnMessage() {
   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setProperties(new Properties());
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertEquals(0L, decoded.getTimestamp());

   Date createTime = new Date(System.currentTimeMillis());

   decoded.setTimestamp(createTime.getTime());
   decoded.reencode();

   assertEquals(createTime.getTime(), decoded.getTimestamp());
   assertEquals(createTime, decoded.getProperties().getCreationTime());
}
 
Example #5
Source File: Benchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void benchmarkProperties() throws IOException {
    Properties properties = new Properties();
    properties.setTo("queue:1-1024");
    properties.setReplyTo("queue:1-11024-reply");
    properties.setMessageId("ID:255f1297-5a71-4df1-8147-b2cdf850a56f:1");
    properties.setCreationTime(new Date(System.currentTimeMillis()));

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        outputBuf.byteBuffer().clear();
        encoder.writeObject(properties);
    }
    resultSet.encodesComplete();

    CompositeReadableBuffer inputBuf = convertToComposite(outputBuf);
    decoder.setBuffer(inputBuf);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        decoder.readObject();
        inputBuf.flip();
    }
    resultSet.decodesComplete();

    time("Properties", resultSet);
}
 
Example #6
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetProperties() {
   MessageImpl protonMessage = createProtonMessage();
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   Properties decoded = message.getProperties();
   assertNotSame(decoded, protonMessage.getProperties());
   assertPropertiesEquals(protonMessage.getProperties(), decoded);

   // Update the values
   decoded.setAbsoluteExpiryTime(new Date(System.currentTimeMillis()));
   decoded.setGroupSequence(UnsignedInteger.valueOf(255));
   decoded.setSubject(UUID.randomUUID().toString());

   // Check that the message is unaffected.
   assertPropertiesNotEquals(protonMessage.getProperties(), decoded);
}
 
Example #7
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetExpirationUpdatesProperties() {
   final Date originalExpirationTime = new Date(System.currentTimeMillis());
   final Date expirationTime = new Date(System.currentTimeMillis());

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setProperties(new Properties());
   protonMessage.setExpiryTime(originalExpirationTime.getTime());
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertEquals(originalExpirationTime.getTime(), decoded.getExpiration());
   decoded.setExpiration(expirationTime.getTime());
   assertEquals(expirationTime.getTime(), decoded.getExpiration());

   decoded.reencode();
   assertEquals(expirationTime, decoded.getProperties().getAbsoluteExpiryTime());
}
 
Example #8
Source File: AMQPPersisterTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private MessageImpl createProtonMessage(String address, byte[] content) {
   MessageImpl message = (MessageImpl) Proton.message();

   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 9));

   Properties properties = new Properties();
   properties.setCreationTime(new Date(System.currentTimeMillis()));
   properties.setTo(address);
   properties.setMessageId(UUID.randomUUID());

   MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>());
   ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>());

   AmqpValue body = new AmqpValue(Arrays.copyOf(content, content.length));

   message.setHeader(header);
   message.setMessageAnnotations(annotations);
   message.setProperties(properties);
   message.setApplicationProperties(applicationProperties);
   message.setBody(body);

   return message;
}
 
Example #9
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Check that getting the ReplyToGroupId returns the expected value from a
 * received messages with a reply-to-group-id.
 */
@Test
public void testGetReplyToGroupIdWithReceivedMessage() {
    String replyToGroupId = "myReplyGroup";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setReplyToGroupId(replyToGroupId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    String actual = amqpMessageFacade.getReplyToGroupId();
    assertNotNull("expected ReplyToGroupId on message was not found", actual);
    assertEquals("expected ReplyToGroupId on message was not found", replyToGroupId, actual);
}
 
Example #10
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetUserIDHasNoEffectOnMessagePropertiesWhenPresentButNoMessageID() {
   final String ID = UUID.randomUUID().toString();

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setProperties(new Properties());
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertNull(decoded.getUserID());
   assertNotNull(decoded.getProperties());
   assertNull(decoded.getProperties().getMessageId());

   decoded.setUserID(ID);
   decoded.reencode();

   assertNull(decoded.getUserID());
   assertNotNull(decoded.getProperties());
   assertNull(decoded.getProperties().getMessageId());
}
 
Example #11
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetUserIDHasNoEffectOnMessagePropertiesWhenPresentWithMessageID() {
   final String ID = UUID.randomUUID().toString();

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setProperties(new Properties());
   protonMessage.setMessageId(ID);
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertNotNull(decoded.getUserID());
   assertNotNull(decoded.getProperties());
   assertNotNull(decoded.getProperties().getMessageId());
   assertEquals(ID, decoded.getUserID());

   decoded.setUserID(ID);
   decoded.reencode();

   assertNotNull(decoded.getUserID());
   assertNotNull(decoded.getProperties());
   assertNotNull(decoded.getProperties().getMessageId());
   assertEquals(ID, decoded.getUserID());
}
 
Example #12
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDestinationWithReceivedMessage() throws JMSException {
    String testToAddress = "myTestAddress";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setTo(testToAddress);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    JmsDestination dest = amqpMessageFacade.getDestination();
    //We didn't set any destination type annotations, so the consumer destination type will be used: a topic.
    assertTrue(dest instanceof Topic);
    assertEquals(testToAddress, ((Topic) dest).getTopicName());
}
 
Example #13
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetReplyToWithReceivedMessage() throws JMSException {
    String testReplyToAddress = "myTestReplyTo";

    Message message = Proton.message();

    Properties props = new Properties();
    props.setReplyTo(testReplyToAddress);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    JmsDestination dest = amqpMessageFacade.getReplyTo();
    //We didn't set any destination type annotations, so the consumer destination type will be used: a topic.
    assertTrue(dest instanceof Topic);
    assertEquals(testReplyToAddress, ((Topic) dest).getTopicName());
}
 
Example #14
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void correlationIdOnReceivedMessageTestImpl(final Object testCorrelationId, final String expected, boolean appSpecificCorrelationId) {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setCorrelationId(testCorrelationId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    String result = amqpMessageFacade.getCorrelationId();
    assertNotNull("Expected a correlationId on received message", result);
    assertEquals("Incorrect correlationId value received", expected, result);
    if(!appSpecificCorrelationId) {
        assertTrue("Should have have 'ID:' prefix", result.startsWith(AmqpMessageIdHelper.JMS_ID_PREFIX));
    }
}
 
Example #15
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void messageIdOnReceivedMessageTestImpl(Object underlyingMessageId, String expected) {
    if (!(underlyingMessageId == null || underlyingMessageId instanceof Binary
            || underlyingMessageId instanceof UnsignedLong || underlyingMessageId instanceof String || underlyingMessageId instanceof UUID)) {
        throw new IllegalArgumentException("invalid id type");
    }

    Message message = Proton.message();

    Properties props = new Properties();
    props.setMessageId(underlyingMessageId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a messageId on received message", amqpMessageFacade.getMessageId());

    assertEquals("Incorrect messageId value received", expected, amqpMessageFacade.getMessageId());
}
 
Example #16
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUserIdOnReceievedMessage() throws Exception {
    String userIdString = "testValue";
    byte[] bytes = userIdString.getBytes("UTF-8");

    Message message = Proton.message();

    Properties props = new Properties();
    props.setUserId(new Binary(bytes));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a userid on received message", amqpMessageFacade.getUserId());
    assertEquals("Incorrect messageId value received", userIdString, amqpMessageFacade.getUserId());
}
 
Example #17
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUserIdBytesOnReceievedMessage() throws Exception {
    String userIdString = "testValue";
    byte[] bytes = userIdString.getBytes("UTF-8");

    Message message = Proton.message();

    message.setUserId(bytes);

    Properties props = new Properties();
    props.setUserId(new Binary(bytes));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a userid on received message", amqpMessageFacade.getUserIdBytes());
    assertArrayEquals("Incorrect userid bytes value received", bytes, amqpMessageFacade.getUserIdBytes());
}
 
Example #18
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGroupSequenceOnReceivedMessageWithGroupSequenceMaxUnsignedIntValue() {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setGroupSequence(UnsignedInteger.valueOf(MAX_UINT));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    // The unsigned int value 2^32-1 will be represented as a negative, and should be the largest such value, -1
    assertEquals("GroupSequence not as expected", -1, amqpMessageFacade.getGroupSequence());
}
 
Example #19
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private boolean isEquals(Properties left, Properties right) {
   if (left == null && right == null) {
      return true;
   }
   if (!isNullnessEquals(left, right)) {
      return false;
   }

   try {
      assertEquals(left.getAbsoluteExpiryTime(), right.getAbsoluteExpiryTime());
      assertEquals(left.getContentEncoding(), right.getAbsoluteExpiryTime());
      assertEquals(left.getContentType(), right.getContentType());
      assertEquals(left.getCorrelationId(), right.getCorrelationId());
      assertEquals(left.getCreationTime(), right.getCreationTime());
      assertEquals(left.getGroupId(), right.getGroupId());
      assertEquals(left.getGroupSequence(), right.getGroupSequence());
      assertEquals(left.getMessageId(), right.getMessageId());
      assertEquals(left.getReplyTo(), right.getReplyTo());
      assertEquals(left.getReplyToGroupId(), right.getReplyToGroupId());
      assertEquals(left.getSubject(), right.getSubject());
      assertEquals(left.getUserId(), right.getUserId());
      assertEquals(left.getTo(), right.getTo());
   } catch (Throwable e) {
      return false;
   }

   return true;
}
 
Example #20
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCorrelationIdBytesOnMessageWithNonBinaryContent() throws Exception {
    AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();

    Properties properties = new Properties();
    properties.setCorrelationId(UUID.randomUUID());

    amqpMessageFacade.setProperties(properties);

    try {
        amqpMessageFacade.getCorrelationIdBytes();
        fail("Should have thrown JMSException");
    } catch (JMSException ex) {}
}
 
Example #21
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUserIdOnReceievedMessageWithEmptyBinaryValue() throws Exception {
    byte[] bytes = new byte[0];

    Message message = Proton.message();

    Properties props = new Properties();
    props.setUserId(new Binary(bytes));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNull("Expected a userid on received message", amqpMessageFacade.getUserId());
}
 
Example #22
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private MessageImpl createProtonMessage() {
   MessageImpl message = (MessageImpl) Proton.message();

   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 9));

   Properties properties = new Properties();
   properties.setCreationTime(new Date(System.currentTimeMillis()));
   properties.setTo(TEST_TO_ADDRESS);
   properties.setMessageId(UUID.randomUUID());

   MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>());
   annotations.getValue().put(Symbol.valueOf(TEST_MESSAGE_ANNOTATION_KEY), TEST_MESSAGE_ANNOTATION_VALUE);

   ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
   applicationProperties.getValue().put(TEST_APPLICATION_PROPERTY_KEY, TEST_APPLICATION_PROPERTY_VALUE);

   AmqpValue body = new AmqpValue(TEST_STRING_BODY);

   message.setHeader(header);
   message.setMessageAnnotations(annotations);
   message.setProperties(properties);
   message.setApplicationProperties(applicationProperties);
   message.setBody(body);

   return message;
}
 
Example #23
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());
}
 
Example #24
Source File: AmqpJmsBytesMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageToSendHasContentTypeSet() throws Exception {
    AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createNewBytesMessageFacade();
    amqpBytesMessageFacade.onSend(0);

    Properties properties = amqpBytesMessageFacade.getProperties();
    assertNotNull(properties);
    assertNotNull(properties.getContentType());

    String contentType = properties.getContentType().toString();
    assertNotNull("content type should be set", contentType);
    assertEquals("application/octet-stream", contentType);
}
 
Example #25
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGroupSequenceOnReceivedMessageWithGroupSequenceJustAboveSignedIntRange() {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setGroupSequence(UnsignedInteger.valueOf(1L + Integer.MAX_VALUE));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    // The unsigned int value >= 2^31 will be represented as a negative, and so should begin from minimum signed int value
    assertEquals("GroupSequence not as expected", Integer.MIN_VALUE, amqpMessageFacade.getGroupSequence());
}
 
Example #26
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetExpirationFromMessageAbsoluteExpirationOVerrideTTL() {
   final Date expirationTime = new Date(System.currentTimeMillis());
   final long ttl = 100000;

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setHeader(new Header());
   protonMessage.setTtl(ttl);
   Properties properties = new Properties();
   properties.setAbsoluteExpiryTime(expirationTime);
   protonMessage.setProperties(properties);
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertEquals(expirationTime.getTime(), decoded.getExpiration());
}
 
Example #27
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetExpirationFromMessageUsingAbsoluteExpirationNegative() {
   final Date expirationTime = new Date(-1);

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   Properties properties = new Properties();
   properties.setAbsoluteExpiryTime(expirationTime);
   protonMessage.setProperties(properties);
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertEquals(0, decoded.getExpiration());
}
 
Example #28
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetExpirationFromMessageUsingAbsoluteExpiration() {
   final Date expirationTime = new Date(System.currentTimeMillis());

   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   Properties properties = new Properties();
   properties.setAbsoluteExpiryTime(expirationTime);
   protonMessage.setProperties(properties);
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertEquals(expirationTime.getTime(), decoded.getExpiration());
}
 
Example #29
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetExpirationFromMessageWithNoTTLInHeaderOrExpirationInProperties() {
   MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
   protonMessage.setHeader(new Header());
   protonMessage.setProperties(new Properties());
   AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage);

   assertEquals(0, decoded.getExpiration());
}
 
Example #30
Source File: MessageHelper.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns a copy of the given message.
 * <p>
 * This is a shallow copy of the <em>Message</em> object, except for the copied <em>Properties</em>.
 *
 * @param message The message to copy.
 * @return The message copy.
 */
public static Message getShallowCopy(final Message message) {
    final Message copy = ProtonHelper.message();
    copy.setDeliveryAnnotations(message.getDeliveryAnnotations());
    copy.setMessageAnnotations(message.getMessageAnnotations());
    if (message.getProperties() != null) {
        copy.setProperties(new Properties(message.getProperties()));
    }
    copy.setApplicationProperties(message.getApplicationProperties());
    copy.setBody(message.getBody());
    copy.setFooter(message.getFooter());
    return copy;
}