Java Code Examples for org.apache.qpid.proton.message.impl.MessageImpl#setApplicationProperties()
The following examples show how to use
org.apache.qpid.proton.message.impl.MessageImpl#setApplicationProperties() .
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: TestConversions.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAmqpValueOfBooleanIsPassedThrough() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); byte[] bodyBytes = new byte[4]; for (int i = 0; i < bodyBytes.length; i++) { bodyBytes[i] = (byte) 0xff; } message.setBody(new AmqpValue(new Boolean(true))); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); verifyProperties(ServerJMSMessage.wrapCoreMessage(serverMessage)); }
Example 3
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleConversionStream() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); List<Object> objects = new LinkedList<>(); objects.add(new Integer(10)); objects.add("10"); message.setBody(new AmqpSequence(objects)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); ServerJMSStreamMessage streamMessage = (ServerJMSStreamMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); verifyProperties(streamMessage); streamMessage.reset(); assertEquals(10, streamMessage.readInt()); assertEquals("10", streamMessage.readString()); }
Example 4
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleConversionText() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); String text = "someText"; message.setBody(new AmqpValue(text)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); ServerJMSTextMessage textMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); textMessage.decode(); verifyProperties(textMessage); assertEquals(text, textMessage.getText()); }
Example 5
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 6
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testSimpleConversionMap() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); Map<String, Object> mapValues = new HashMap<>(); mapValues.put("somestr", "value"); mapValues.put("someint", Integer.valueOf(1)); 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")); AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage(), null); assertNotNull(newAMQP.getBody()); }
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 |
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 10
Source File: MessageTransformationTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testComplexQpidJMSMessageEncodeDecode() throws Exception { 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); messageAnnotations.put(Symbol.valueOf("x-opt-jms-reply-to"), 0); messageAnnotations.put(Symbol.valueOf("x-opt-delivery-delay"), 2000); 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.")); ICoreMessage core = encodeAndCreateAMQPMessage(message).toCore(); AMQPMessage outboudMessage = AMQPConverter.getInstance().fromCore(core, null); assertEquals(10, outboudMessage.getApplicationProperties().getValue().size()); assertEquals(4, outboudMessage.getMessageAnnotations().getValue().size()); }
Example 11
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; }
Example 12
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 13
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void testConvertMessageWithMapInFooter() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); final String footerName = "test-footer"; final Symbol footerNameSymbol = Symbol.valueOf(footerName); Map<String, String> embeddedMap = new LinkedHashMap<>(); embeddedMap.put("key1", "value1"); embeddedMap.put("key2", "value2"); embeddedMap.put("key3", "value3"); Map<Symbol, Object> footerMap = new LinkedHashMap<>(); footerMap.put(footerNameSymbol, embeddedMap); Footer messageFooter = new Footer(footerMap); byte[] encodedEmbeddedMap = encodeObject(embeddedMap); Map<String, Object> mapValues = new HashMap<>(); mapValues.put("somestr", "value"); mapValues.put("someint", Integer.valueOf(1)); message.setFooter(messageFooter); 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_FOOTER_PREFIX + footerName)); assertArrayEquals(encodedEmbeddedMap, (byte[]) mapMessage.getObjectProperty(JMS_AMQP_ENCODED_FOOTER_PREFIX + footerName)); AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage(), null); assertNotNull(newAMQP.getBody()); assertNotNull(newAMQP.getFooter()); assertNotNull(newAMQP.getFooter().getValue()); assertTrue(newAMQP.getFooter().getValue().containsKey(footerNameSymbol)); Object result = newAMQP.getFooter().getValue().get(footerNameSymbol); assertTrue(result instanceof Map); assertEquals(embeddedMap, (Map<String, String>) result); }
Example 14
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 15
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testSimpleConversionBytes() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); byte[] bodyBytes = new byte[4]; for (int i = 0; i < bodyBytes.length; i++) { bodyBytes[i] = (byte) 0xff; } message.setBody(new Data(new Binary(bodyBytes))); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); ServerJMSBytesMessage bytesMessage = (ServerJMSBytesMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); verifyProperties(bytesMessage); assertEquals(bodyBytes.length, bytesMessage.getBodyLength()); byte[] newBodyBytes = new byte[4]; bytesMessage.readBytes(newBodyBytes); Assert.assertArrayEquals(bodyBytes, newBodyBytes); }