Java Code Examples for org.apache.qpid.proton.message.impl.MessageImpl#setMessageAnnotations()
The following examples show how to use
org.apache.qpid.proton.message.impl.MessageImpl#setMessageAnnotations() .
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: JMSTransformationSpeedComparisonTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private MessageImpl createTypicalQpidJMSMessage() { Map<String, Object> applicationProperties = new HashMap<>(); Map<Symbol, Object> messageAnnotations = new HashMap<>(); applicationProperties.put("property-1", "string"); applicationProperties.put("property-2", 512); applicationProperties.put("property-3", true); messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0); messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0); MessageImpl message = (MessageImpl) Proton.message(); message.setAddress("queue://test-queue"); message.setDeliveryCount(1); message.setApplicationProperties(new ApplicationProperties(applicationProperties)); message.setMessageAnnotations(new MessageAnnotations(messageAnnotations)); message.setCreationTime(System.currentTimeMillis()); message.setContentType("text/plain"); message.setBody(new AmqpValue("String payload for AMQP message conversion performance testing.")); return message; }
Example 2
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetScheduledDeliveryTimeMessageSentWithFixedTime() { final long scheduledTime = System.currentTimeMillis(); final long newScheduledTime = System.currentTimeMillis() + 1000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME, scheduledTime); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(scheduledTime, decoded.getScheduledDeliveryTime().longValue()); decoded.setScheduledDeliveryTime(newScheduledTime); assertEquals(newScheduledTime, decoded.getScheduledDeliveryTime().longValue()); decoded.reencode(); assertEquals(newScheduledTime, decoded.getMessageAnnotations().getValue().get(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME)); }
Example 3
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetScheduledDeliveryTimeMessageSentWithFixedDelay() { final long scheduledDelay = 100000; final long newScheduledTime = System.currentTimeMillis() + 1000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_DELAY, scheduledDelay); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertTrue(decoded.getScheduledDeliveryTime().longValue() > System.currentTimeMillis()); decoded.setScheduledDeliveryTime(newScheduledTime); assertEquals(newScheduledTime, decoded.getScheduledDeliveryTime().longValue()); decoded.reencode(); assertEquals(newScheduledTime, decoded.getMessageAnnotations().getValue().get(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME)); }
Example 4
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 5
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception { String toAddress = "toAddress"; MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue("myTextMessageContent")); message.setAddress(toAddress); if (toTypeAnnotationValue != null) { Map<Symbol, Object> map = new HashMap<>(); map.put(Symbol.valueOf("x-opt-to-type"), toTypeAnnotationValue); MessageAnnotations ma = new MessageAnnotations(map); message.setMessageAnnotations(ma); } javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); }
Example 6
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetScheduledDeliveryTimeToNoneClearsDelayAndTimeValues() { final long scheduledTime = System.currentTimeMillis(); final long scheduledDelay = 100000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_DELAY, scheduledDelay); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME, scheduledTime); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(scheduledTime, decoded.getScheduledDeliveryTime().longValue()); decoded.setScheduledDeliveryTime((long) 0); decoded.reencode(); assertNull(decoded.getMessageAnnotations().getValue().get(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME)); assertNull(decoded.getMessageAnnotations().getValue().get(AMQPMessageSupport.SCHEDULED_DELIVERY_DELAY)); }
Example 7
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testEditAndConvert() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); properties.getValue().put("hello", "hello"); MessageImpl message = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); message.setMessageAnnotations(annotations); message.setApplicationProperties(properties); String text = "someText"; message.setBody(new AmqpValue(text)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); TypedProperties extraProperties = new TypedProperties(); encodedMessage.setAddress(SimpleString.toSimpleString("xxxx.v1.queue")); for (int i = 0; i < 10; i++) { if (logger.isDebugEnabled()) { logger.debug("Message encoded :: " + encodedMessage.toDebugString()); } encodedMessage.messageChanged(); AmqpValue value = (AmqpValue) encodedMessage.getProtonMessage().getBody(); Assert.assertEquals(text, (String) value.getValue()); // this line is needed to force a failure ICoreMessage coreMessage = encodedMessage.toCore(); if (logger.isDebugEnabled()) { logger.debug("Converted message: " + coreMessage); } } }
Example 8
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testExpandNoReencode() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); properties.getValue().put("hello", "hello"); MessageImpl message = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); message.setMessageAnnotations(annotations); message.setApplicationProperties(properties); String text = "someText"; message.setBody(new AmqpValue(text)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); TypedProperties extraProperties = new TypedProperties(); encodedMessage.setAddress(SimpleString.toSimpleString("xxxx.v1.queue")); for (int i = 0; i < 100; i++) { encodedMessage.setMessageID(333L); if (i % 3 == 0) { encodedMessage.referenceOriginalMessage(encodedMessage, "SOME-OTHER-QUEUE-DOES-NOT-MATTER-WHAT"); } else { encodedMessage.referenceOriginalMessage(encodedMessage, "XXX"); } encodedMessage.putStringProperty("another " + i, "value " + i); encodedMessage.messageChanged(); if (i % 2 == 0) { encodedMessage.setAddress("THIS-IS-A-BIG-THIS-IS-A-BIG-ADDRESS-THIS-IS-A-BIG-ADDRESS-RIGHT"); } else { encodedMessage.setAddress("A"); // small address } encodedMessage.messageChanged(); ICoreMessage coreMessage = encodedMessage.toCore(); } }
Example 9
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetRoutingTypeFromMessageWithAnyCastType() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.ROUTING_TYPE, RoutingType.ANYCAST.getType()); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(RoutingType.ANYCAST, decoded.getRoutingType()); }
Example 10
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetRoutingTypeFromMessageWithMulticastType() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.ROUTING_TYPE, RoutingType.MULTICAST.getType()); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(RoutingType.MULTICAST, decoded.getRoutingType()); }
Example 11
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetRoutingTypeFromMessageWithQueueType() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION, AMQPMessageSupport.QUEUE_TYPE); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(RoutingType.ANYCAST, decoded.getRoutingType()); }
Example 12
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 13
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetRoutingTypeFromMessageWithTopicType() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION, AMQPMessageSupport.TOPIC_TYPE); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(RoutingType.MULTICAST, decoded.getRoutingType()); }
Example 14
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetRoutingTypeFromMessageWithTempTopicType() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION, AMQPMessageSupport.TEMP_TOPIC_TYPE); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(RoutingType.MULTICAST, decoded.getRoutingType()); }
Example 15
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetRoutingTypeFromMessageWithUnknownType() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION, (byte) 32); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertNull(decoded.getRoutingType()); }
Example 16
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetScheduledDeliveryTimeMessageSentWithFixedTime() { final long scheduledTime = System.currentTimeMillis(); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME, scheduledTime); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(scheduledTime, decoded.getScheduledDeliveryTime().longValue()); }
Example 17
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetScheduledDeliveryTimeMessageSentWithFixedTimeAndDelay() { final long scheduledTime = System.currentTimeMillis(); final long scheduledDelay = 100000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_DELAY, scheduledDelay); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME, scheduledTime); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(scheduledTime, decoded.getScheduledDeliveryTime().longValue()); }
Example 18
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetScheduledDeliveryTimeMessageSentWithFixedDelay() { final long scheduledDelay = 100000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); MessageAnnotations annotations = new MessageAnnotations(new HashMap<>()); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_DELAY, scheduledDelay); protonMessage.setMessageAnnotations(annotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertTrue(decoded.getScheduledDeliveryTime().longValue() > System.currentTimeMillis()); }
Example 19
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void testConvertMessageWithMapInMessageAnnotations() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); final String annotationName = "x-opt-test-annotation"; final Symbol annotationNameSymbol = Symbol.valueOf(annotationName); Map<String, String> embeddedMap = new LinkedHashMap<>(); embeddedMap.put("key1", "value1"); embeddedMap.put("key2", "value2"); embeddedMap.put("key3", "value3"); Map<Symbol, Object> annotationsMap = new LinkedHashMap<>(); annotationsMap.put(annotationNameSymbol, embeddedMap); MessageAnnotations messageAnnotations = new MessageAnnotations(annotationsMap); byte[] encodedEmbeddedMap = encodeObject(embeddedMap); Map<String, Object> mapValues = new HashMap<>(); mapValues.put("somestr", "value"); mapValues.put("someint", Integer.valueOf(1)); message.setMessageAnnotations(messageAnnotations); message.setBody(new AmqpValue(mapValues)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); serverMessage.getReadOnlyBodyBuffer(); ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); mapMessage.decode(); verifyProperties(mapMessage); assertEquals(1, mapMessage.getInt("someint")); assertEquals("value", mapMessage.getString("somestr")); assertTrue(mapMessage.propertyExists(JMS_AMQP_ENCODED_MESSAGE_ANNOTATION_PREFIX + annotationName)); assertArrayEquals(encodedEmbeddedMap, (byte[]) mapMessage.getObjectProperty(JMS_AMQP_ENCODED_MESSAGE_ANNOTATION_PREFIX + annotationName)); AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage(), null); assertNotNull(newAMQP.getBody()); assertNotNull(newAMQP.getMessageAnnotations()); assertNotNull(newAMQP.getMessageAnnotations().getValue()); assertTrue(newAMQP.getMessageAnnotations().getValue().containsKey(annotationNameSymbol)); Object result = newAMQP.getMessageAnnotations().getValue().get(annotationNameSymbol); assertTrue(result instanceof Map); assertEquals(embeddedMap, (Map<String, String>) result); }
Example 20
Source File: JMSTransformationSpeedComparisonTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private MessageImpl createComplexQpidJMSMessage() { Map<String, Object> applicationProperties = new HashMap<>(); Map<Symbol, Object> messageAnnotations = new HashMap<>(); applicationProperties.put("property-1", "string-1"); applicationProperties.put("property-2", 512); applicationProperties.put("property-3", true); applicationProperties.put("property-4", "string-2"); applicationProperties.put("property-5", 512); applicationProperties.put("property-6", true); applicationProperties.put("property-7", "string-3"); applicationProperties.put("property-8", 512); applicationProperties.put("property-9", true); messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0); messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0); MessageImpl message = (MessageImpl) Proton.message(); // Header Values message.setPriority((short) 9); message.setDurable(true); message.setDeliveryCount(2); message.setTtl(5000); // Properties message.setMessageId("ID:SomeQualifier:0:0:1"); message.setGroupId("Group-ID-1"); message.setGroupSequence(15); message.setAddress("queue://test-queue"); message.setReplyTo("queue://reply-queue"); message.setCreationTime(System.currentTimeMillis()); message.setContentType("text/plain"); message.setCorrelationId("ID:SomeQualifier:0:7:9"); message.setUserId("username".getBytes(StandardCharsets.UTF_8)); // Application Properties / Message Annotations / Body message.setApplicationProperties(new ApplicationProperties(applicationProperties)); message.setMessageAnnotations(new MessageAnnotations(messageAnnotations)); message.setBody(new AmqpValue("String payload for AMQP message conversion performance testing.")); return message; }