Java Code Examples for org.apache.qpid.proton.message.impl.MessageImpl#setHeader()
The following examples show how to use
org.apache.qpid.proton.message.impl.MessageImpl#setHeader() .
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: AMQPPersisterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
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 2
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetExpirationToClearUpdateHeader() { final long ttl = 100000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setTtl(ttl); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertTrue(decoded.getExpiration() > System.currentTimeMillis()); decoded.setExpiration(-1); decoded.reencode(); assertEquals(0, decoded.getExpiration()); assertNull(decoded.getHeader().getTtl()); }
Example 3
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testNonDurableMessageReencodedToDurable() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertFalse(decoded.isDurable()); // Underlying message data not updated yet assertNull(decoded.getHeader().getDurable()); decoded.setDurable(true); decoded.reencode(); assertTrue(decoded.isDurable()); // Underlying message data now updated assertTrue(decoded.getHeader().getDurable()); }
Example 4
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetAddressFromMessage() { final String ADDRESS = "myQueue"; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setAddress(ADDRESS); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(ADDRESS, decoded.getAddress()); }
Example 5
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetTimestampFromMessageWithNoCreateTimeSet() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(0L, decoded.getTimestamp()); }
Example 6
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetTimestampFromMessage() { Date timestamp = new Date(System.currentTimeMillis()); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); Properties properties = new Properties(); properties.setCreationTime(timestamp); protonMessage.setProperties(properties); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(timestamp.getTime(), decoded.getTimestamp()); }
Example 7
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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 8
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetExpirationFromMessageUsingTTL() { final long ttl = 100000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setTtl(ttl); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertTrue(decoded.getExpiration() > System.currentTimeMillis()); }
Example 9
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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 10
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetExpirationFromMessageWithNoTTLInHeader() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(0, decoded.getExpiration()); }
Example 11
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testSetPriorityOnMessageWithHeader() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(AMQPStandardMessage.DEFAULT_MESSAGE_PRIORITY, decoded.getPriority()); decoded.setPriority((byte) 9); decoded.reencode(); assertEquals(9, decoded.getPriority()); assertEquals(9, decoded.getHeader().getPriority().byteValue()); }
Example 12
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetPriorityFromMessageWithNoPrioritySet() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(AMQPStandardMessage.DEFAULT_MESSAGE_PRIORITY, decoded.getPriority()); }
Example 13
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetPriorityFromMessage() { final short PRIORITY = 7; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setPriority(PRIORITY); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(PRIORITY, decoded.getPriority()); }
Example 14
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
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 15
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetGroupIDFromMessage() { final String GROUP_ID = "group-1"; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setGroupId(GROUP_ID); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(GROUP_ID, decoded.getGroupID().toString()); }
Example 16
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testIsDurableFromMessageWithHeaderTaggedAsFalse() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setDurable(false); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertFalse(decoded.isDurable()); }
Example 17
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testIsDurableFromMessageWithHeaderTaggedAsTrue() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setDurable(true); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertTrue(decoded.isDurable()); }
Example 18
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetAddressSimpleStringFromMessage() { final String ADDRESS = "myQueue"; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setAddress(ADDRESS); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(ADDRESS, decoded.getAddressSimpleString().toString()); }
Example 19
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testDecodeMultiThreaded() throws Exception { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader( new Header()); Properties properties = new Properties(); properties.setTo("someNiceLocal"); protonMessage.setProperties(properties); protonMessage.getHeader().setDeliveryCount(new UnsignedInteger(7)); protonMessage.getHeader().setDurable(Boolean.TRUE); protonMessage.setApplicationProperties(new ApplicationProperties(new HashMap<>())); final AtomicInteger failures = new AtomicInteger(0); for (int testTry = 0; testTry < 100; testTry++) { AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); Thread[] threads = new Thread[100]; CountDownLatch latchAlign = new CountDownLatch(threads.length); CountDownLatch go = new CountDownLatch(1); Runnable run = new Runnable() { @Override public void run() { try { latchAlign.countDown(); go.await(); Assert.assertNotNull(decoded.getHeader()); // this is a method used by Core Converter decoded.getProtonMessage(); Assert.assertNotNull(decoded.getHeader()); } catch (Throwable e) { e.printStackTrace(); failures.incrementAndGet(); } } }; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(run); threads[i].start(); } Assert.assertTrue(latchAlign.await(10, TimeUnit.SECONDS)); go.countDown(); for (Thread thread : threads) { thread.join(5000); Assert.assertFalse(thread.isAlive()); } Assert.assertEquals(0, failures.get()); } }
Example 20
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testGetSendBufferWithDeliveryAnnotations() { 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")); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); DeliveryAnnotations newDeliveryAnnotations = new DeliveryAnnotations(new HashMap<>()); final String annotationKey = "annotationKey"; final String annotationValue = "annotationValue"; newDeliveryAnnotations.getValue().put(Symbol.getSymbol(annotationKey), annotationValue); decoded.setDeliveryAnnotationsForSendBuffer(newDeliveryAnnotations); ReadableBuffer sendBuffer = decoded.getSendBuffer(1); assertEquals(decoded.getEncodeSize(), sendBuffer.capacity()); AMQPStandardMessage msgFromSendBuffer = new AMQPStandardMessage(0, sendBuffer, null, null); assertEquals("someNiceLocal", msgFromSendBuffer.getAddress()); assertNotNull(msgFromSendBuffer.getDeliveryAnnotations()); assertEquals(1, msgFromSendBuffer.getDeliveryAnnotations().getValue().size()); assertEquals(annotationValue, msgFromSendBuffer.getDeliveryAnnotations().getValue().get(Symbol.getSymbol(annotationKey))); // again with higher deliveryCount DeliveryAnnotations newDeliveryAnnotations2 = new DeliveryAnnotations(new HashMap<>()); final String annotationKey2 = "annotationKey2"; final String annotationValue2 = "annotationValue2"; newDeliveryAnnotations2.getValue().put(Symbol.getSymbol(annotationKey2), annotationValue2); decoded.setDeliveryAnnotationsForSendBuffer(newDeliveryAnnotations2); ReadableBuffer sendBuffer2 = decoded.getSendBuffer(5); assertEquals(decoded.getEncodeSize(), sendBuffer2.capacity()); AMQPStandardMessage msgFromSendBuffer2 = new AMQPStandardMessage(0, sendBuffer2, null, null); assertEquals("someNiceLocal", msgFromSendBuffer2.getAddress()); assertNotNull(msgFromSendBuffer2.getDeliveryAnnotations()); assertEquals(1, msgFromSendBuffer2.getDeliveryAnnotations().getValue().size()); assertEquals(annotationValue2, msgFromSendBuffer2.getDeliveryAnnotations().getValue().get(Symbol.getSymbol(annotationKey2))); }