Java Code Examples for org.apache.qpid.proton.message.Message#setMessageAnnotations()
The following examples show how to use
org.apache.qpid.proton.message.Message#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: AmqpRawMessageConverter.java From strimzi-kafka-bridge with Apache License 2.0 | 6 votes |
@Override public Message toMessage(String address, KafkaConsumerRecord<String, byte[]> record) { Message message = Proton.message(); message.setAddress(address); message.decode(record.value(), 0, record.value().length); // put message annotations about partition, offset and key (if not null) Map<Symbol, Object> map = new HashMap<>(); map.put(Symbol.valueOf(AmqpBridge.AMQP_PARTITION_ANNOTATION), record.partition()); map.put(Symbol.valueOf(AmqpBridge.AMQP_OFFSET_ANNOTATION), record.offset()); map.put(Symbol.valueOf(AmqpBridge.AMQP_KEY_ANNOTATION), record.key()); map.put(Symbol.valueOf(AmqpBridge.AMQP_TOPIC_ANNOTATION), record.topic()); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); return message; }
Example 2
Source File: AmqpDefaultMessageConverter.java From strimzi-kafka-bridge with Apache License 2.0 | 6 votes |
@Override public Message toMessage(String address, KafkaConsumerRecord<String, byte[]> record) { Message message = Proton.message(); message.setAddress(address); // put message annotations about partition, offset and key (if not null) Map<Symbol, Object> map = new HashMap<>(); map.put(Symbol.valueOf(AmqpBridge.AMQP_PARTITION_ANNOTATION), record.partition()); map.put(Symbol.valueOf(AmqpBridge.AMQP_OFFSET_ANNOTATION), record.offset()); map.put(Symbol.valueOf(AmqpBridge.AMQP_KEY_ANNOTATION), record.key()); map.put(Symbol.valueOf(AmqpBridge.AMQP_TOPIC_ANNOTATION), record.topic()); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); message.setBody(new Data(new Binary(record.value()))); return message; }
Example 3
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testMessageAnnotationExistsUsingReceivedMessageWithMessageAnnotationsSection() { Symbol symbolKeyName = Symbol.valueOf("myTestSymbolName"); String value = "myTestValue"; Message message = Proton.message(); Map<Symbol, Object> annotationsMap = new HashMap<Symbol, Object>(); annotationsMap.put(symbolKeyName, value); message.setMessageAnnotations(new MessageAnnotations(annotationsMap)); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); assertTrue(amqpMessageFacade.messageAnnotationExists(symbolKeyName)); assertFalse(amqpMessageFacade.messageAnnotationExists(Symbol.valueOf("otherName"))); }
Example 4
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testGetMessageAnnotationUsingReceivedMessage() { Symbol symbolKeyName = Symbol.valueOf("myTestSymbolName"); String value = "myTestValue"; Message message = Proton.message(); Map<Symbol, Object> annotationsMap = new HashMap<Symbol, Object>(); annotationsMap.put(symbolKeyName, value); message.setMessageAnnotations(new MessageAnnotations(annotationsMap)); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); assertEquals(value, amqpMessageFacade.getMessageAnnotation(symbolKeyName)); assertNull(amqpMessageFacade.getMessageAnnotation(Symbol.valueOf("otherName"))); }
Example 5
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testRemoveMessageAnnotation() { Symbol symbolKeyName = Symbol.valueOf("myTestSymbolName"); String value = "myTestValue"; Message message = Proton.message(); Map<Symbol, Object> annotationsMap = new HashMap<Symbol, Object>(); annotationsMap.put(symbolKeyName, value); message.setMessageAnnotations(new MessageAnnotations(annotationsMap)); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); assertEquals(value, amqpMessageFacade.getMessageAnnotation(symbolKeyName)); assertNull(amqpMessageFacade.getMessageAnnotation(Symbol.valueOf("otherName"))); amqpMessageFacade.removeMessageAnnotation(symbolKeyName); assertNull(amqpMessageFacade.getMessageAnnotation(symbolKeyName)); }
Example 6
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testClearAllMessageAnnotationsUsingReceivedMessageWithMessageAnnotationsSection() { String symbolKeyName = "myTestSymbolName"; String value = "myTestValue"; Message message = Proton.message(); Map<Symbol, Object> annotationsMap = new HashMap<Symbol, Object>(); annotationsMap.put(Symbol.valueOf(symbolKeyName), value); message.setMessageAnnotations(new MessageAnnotations(annotationsMap)); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); amqpMessageFacade.clearMessageAnnotations(); assertNull(amqpMessageFacade.getMessageAnnotations()); }
Example 7
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_MESSAGE} is * treated as a generic {@link JmsMessage} with {@link AmqpJmsMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateGenericMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsMessageFacade.class, facade.getClass()); }
Example 8
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_BYTES_MESSAGE} is * treated as a {@link JmsBytesMessage} with {@link AmqpJmsBytesMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateBytesMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_BYTES_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass()); }
Example 9
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_BYTES_MESSAGE} is * treated as a {@link JmsTextMessage} with {@link AmqpJmsTextMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateTextMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_TEXT_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass()); }
Example 10
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_STREAM_MESSAGE} is * treated as a {@link JmsStreamMessage} with {@link AmqpJmsStreamMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test public void testCreateStreamMessageFromMessageTypeAnnotation() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_STREAM_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsStreamMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsStreamMessageFacade.class, facade.getClass()); }
Example 11
Source File: MessageHelper.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * 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; }
Example 12
Source File: AMQPMessageSupportTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetMessageAnnotationWhenMessageHasAnnotationsMap() { Map<Symbol, Object> messageAnnotationsMap = new HashMap<>(); messageAnnotationsMap.put(Symbol.valueOf("x-opt-test"), Boolean.TRUE); Message message = Proton.message(); message.setMessageAnnotations(new MessageAnnotations(messageAnnotationsMap)); assertNotNull(AMQPMessageSupport.getMessageAnnotation("x-opt-test", message)); }
Example 13
Source File: AMQPMessageSupportTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetMessageAnnotationWhenMessageHasEmptyAnnotationsMap() { Map<Symbol, Object> messageAnnotationsMap = new HashMap<>(); Message message = Proton.message(); message.setMessageAnnotations(new MessageAnnotations(messageAnnotationsMap)); assertNull(AMQPMessageSupport.getMessageAnnotation("x-opt-test", message)); }
Example 14
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that a message with the {@value AmqpMessageSupport#JMS_MSG_TYPE} * annotation set to {@value AmqpMessageSupport#JMS_MESSAGE} is * treated as a generic {@link JmsMessage} with {@link AmqpJmsMessageFacade} * * @throws Exception if an error occurs during the test. */ @Test(expected = IOException.class) public void testCreateMessageFromUnknownMessageTypeAnnotationValueThrows() throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, (byte) -1); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)); }
Example 15
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void createObjectMessageFromMessageTypeAnnotationTestImpl(boolean setJavaSerializedContentType) throws Exception { Message message = Proton.message(); Map<Symbol, Object> map = new HashMap<Symbol, Object>(); map.put(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_OBJECT_MESSAGE); MessageAnnotations messageAnnotations = new MessageAnnotations(map); message.setMessageAnnotations(messageAnnotations); if (setJavaSerializedContentType) { message.setContentType(AmqpMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString()); } JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsObjectMessage.class, jmsMessage.getClass()); JmsMessageFacade facade = jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals("Unexpected facade class type", AmqpJmsObjectMessageFacade.class, facade.getClass()); AmqpObjectTypeDelegate delegate = ((AmqpJmsObjectMessageFacade) facade).getDelegate(); if (setJavaSerializedContentType) { assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpSerializedObjectDelegate); } else { assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpTypedObjectDelegate); } }