org.apache.qpid.proton.amqp.messaging.MessageAnnotations Java Examples
The following examples show how to use
org.apache.qpid.proton.amqp.messaging.MessageAnnotations.
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 |
@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 #2
Source File: FastPathMessageAnnotationsType.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void write(MessageAnnotations val) { WritableBuffer buffer = getEncoder().getBuffer(); buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR); buffer.put(EncodingCodes.SMALLULONG); buffer.put(DESCRIPTOR_CODE); MapType mapType = (MapType) getEncoder().getType(val.getValue()); mapType.setKeyEncoding(symbolType); try { mapType.write(val.getValue()); } finally { mapType.setKeyEncoding(null); } }
Example #3
Source File: Benchmark.java From qpid-proton-j with Apache License 2.0 | 6 votes |
private void benchmarkMessageAnnotations() throws IOException { MessageAnnotations annotations = new MessageAnnotations(new HashMap<Symbol, Object>()); annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128)); annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128)); annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128)); resultSet.start(); for (int i = 0; i < ITERATIONS; i++) { outputBuf.byteBuffer().clear(); encoder.writeObject(annotations); } 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("MessageAnnotations", resultSet); }
Example #4
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 #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: JMSMappingOutboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void doTestConvertMessageWithJMSReplyTo(Destination jmsReplyTo, Object expectedAnnotationValue) throws Exception { ServerJMSTextMessage textMessage = createTextMessage(); textMessage.setText("myTextMessageContent"); textMessage.setJMSReplyTo(jmsReplyTo); AMQPMessage amqp = AMQPConverter.getInstance().fromCore(textMessage.getInnerMessage(), null); MessageAnnotations ma = amqp.getMessageAnnotations(); Map<Symbol, Object> maMap = ma == null ? null : ma.getValue(); if (maMap != null) { Object actualValue = maMap.get(AMQPMessageSupport.JMS_REPLY_TO_TYPE_MSG_ANNOTATION); assertEquals("Unexpected annotation value", expectedAnnotationValue, actualValue); } else if (expectedAnnotationValue != null) { fail("Expected annotation value, but there were no annotations"); } if (jmsReplyTo != null) { assertEquals("Unexpected 'reply-to' address", AMQPMessageSupport.toAddress(jmsReplyTo).toString(), amqp.getReplyTo().toString()); } }
Example #7
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 #8
Source File: AmqpCoreConverter.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected static ServerJMSMessage processMessageAnnotations(ServerJMSMessage jms, MessageAnnotations annotations) throws Exception { if (annotations != null && annotations.getValue() != null) { for (Map.Entry<?, ?> entry : annotations.getValue().entrySet()) { String key = entry.getKey().toString(); if ("x-opt-delivery-time".equals(key) && entry.getValue() != null) { long deliveryTime = ((Number) entry.getValue()).longValue(); jms.setLongProperty(HDR_SCHEDULED_DELIVERY_TIME.toString(), deliveryTime); } else if ("x-opt-delivery-delay".equals(key) && entry.getValue() != null) { long delay = ((Number) entry.getValue()).longValue(); if (delay > 0) { jms.setLongProperty(HDR_SCHEDULED_DELIVERY_TIME.toString(), System.currentTimeMillis() + delay); } } try { setProperty(jms, JMS_AMQP_MESSAGE_ANNOTATION_PREFIX + key, entry.getValue()); } catch (ActiveMQPropertyConversionException e) { encodeUnsupportedMessagePropertyType(jms, JMS_AMQP_ENCODED_MESSAGE_ANNOTATION_PREFIX + key, entry.getValue()); } } } return jms; }
Example #9
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 #10
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testSetMessageAnnotationsOnNewMessage() { Symbol symbolKeyName = Symbol.valueOf("myTestSymbolName"); Symbol symbolKeyName2 = Symbol.valueOf("myTestSymbolName2"); String value = "myTestValue"; AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade(); // check setting first annotation amqpMessageFacade.setMessageAnnotation(symbolKeyName, value); MessageAnnotations underlyingAnnotations = amqpMessageFacade.getMessageAnnotations(); assertNotNull(underlyingAnnotations); assertTrue(underlyingAnnotations.getValue().containsKey(symbolKeyName)); assertEquals(value, underlyingAnnotations.getValue().get(symbolKeyName)); // set another amqpMessageFacade.setMessageAnnotation(symbolKeyName2, value); assertTrue(underlyingAnnotations.getValue().containsKey(symbolKeyName)); assertTrue(underlyingAnnotations.getValue().containsKey(symbolKeyName2)); }
Example #11
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 #12
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(Object replyToTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception { String replyToAddress = "replyToAddress"; MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue("myTextMessageContent")); message.setReplyTo(replyToAddress); if (replyToTypeAnnotationValue != null) { Map<Symbol, Object> map = new HashMap<>(); map.put(Symbol.valueOf("x-opt-reply-type"), replyToTypeAnnotationValue); MessageAnnotations ma = new MessageAnnotations(map); message.setMessageAnnotations(ma); } javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); }
Example #13
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 #14
Source File: AMQPMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected Map<Symbol, Object> getMessageAnnotationsMap(boolean createIfAbsent) { Map<Symbol, Object> map = null; if (messageAnnotations != null) { map = messageAnnotations.getValue(); } if (map == null) { if (createIfAbsent) { map = new HashMap<>(); this.messageAnnotations = new MessageAnnotations(map); } else { map = Collections.EMPTY_MAP; } } return map; }
Example #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
Source File: AmqpCodec.java From qpid-jms with Apache License 2.0 | 6 votes |
private static AmqpJmsMessageFacade createFromMsgAnnotation(MessageAnnotations messageAnnotations) throws IOException { Object annotation = AmqpMessageSupport.getMessageAnnotation(JMS_MSG_TYPE, messageAnnotations); if (annotation != null) { switch ((byte) annotation) { case JMS_MESSAGE: return new AmqpJmsMessageFacade(); case JMS_BYTES_MESSAGE: return new AmqpJmsBytesMessageFacade(); case JMS_TEXT_MESSAGE: return new AmqpJmsTextMessageFacade(StandardCharsets.UTF_8); case JMS_MAP_MESSAGE: return new AmqpJmsMapMessageFacade(); case JMS_STREAM_MESSAGE: return new AmqpJmsStreamMessageFacade(); case JMS_OBJECT_MESSAGE: return new AmqpJmsObjectMessageFacade(); default: throw new IOException("Invalid JMS Message Type annotation value found in message: " + annotation); } } return null; }
Example #22
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private boolean isEquals(MessageAnnotations left, MessageAnnotations right) { if (left == null && right == null) { return true; } if (!isNullnessEquals(left, right)) { return false; } return isEquals(left.getValue(), right.getValue()); }
Example #23
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetMessageAnnotations() { MessageImpl protonMessage = createProtonMessage(); AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null); MessageAnnotations decoded = message.getMessageAnnotations(); assertNotSame(decoded, protonMessage.getMessageAnnotations()); assertMessageAnnotationsEquals(protonMessage.getMessageAnnotations(), decoded); // Update the values decoded.getValue().put(Symbol.valueOf(UUID.randomUUID().toString()), "test"); // Check that the message is unaffected. assertMessageAnnotationsNotEquals(protonMessage.getMessageAnnotations(), decoded); }
Example #24
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doTestJMSMessageEncodingAddsProperMessageAnnotations(byte msgType, byte toType, byte replyToType) throws Exception { final AmqpJmsMessageFacade message = createMessageFacadeFromTypeId(msgType); final JmsDestination to = createDestinationFromTypeId(toType); final JmsDestination replyTo = createDestinationFromTypeId(replyToType); message.setDestination(to); message.setReplyTo(replyTo); // Allows the code to run through what should be cached in the TLS portion of the codec // and not be using the globally cached bits, this checks that nothing NPEs or otherwise // fails and should show in test coverage that the cache fill + cache use is exercised. for (int i = 0; i <= 2; ++i) { MessageImpl amqpMessage = (MessageImpl) AmqpMessageSupport.decodeMessage(AmqpCodec.encodeMessage(message)); MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations(); assertNotNull(messageAnnotations); assertNotNull(messageAnnotations.getValue()); Map<Symbol, Object> messageAnnotationsMap = messageAnnotations.getValue(); assertTrue(messageAnnotationsMap.containsKey(AmqpMessageSupport.JMS_MSG_TYPE)); if (toType != AmqpDestinationHelper.UNKNOWN_TYPE) { assertTrue(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); assertEquals(toType, messageAnnotationsMap.get(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); } else { assertFalse(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); } if (replyToType != AmqpDestinationHelper.UNKNOWN_TYPE) { assertTrue(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL)); assertEquals(replyToType, messageAnnotationsMap.get(AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL)); } else { assertFalse(messageAnnotationsMap.containsKey(AmqpDestinationHelper.JMS_REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL)); } } }
Example #25
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 #26
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 #27
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testHasScheduledDeliveryTimeReloadPersistence() { final long scheduledTime = System.currentTimeMillis(); MessageImpl protonMessage = createProtonMessage(); MessageAnnotations annotations = protonMessage.getMessageAnnotations(); annotations.getValue().put(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME, scheduledTime); ActiveMQBuffer encoded = encodeMessageAsPersistedBuffer(protonMessage); AMQPMessage message = new AMQPStandardMessage(0); try { message.getProtonMessage(); fail("Should throw NPE due to not being initialized yet"); } catch (NullPointerException npe) { } Assert.assertEquals(AMQPMessage.MessageDataScanningStatus.NOT_SCANNED, message.messageDataScanned()); // Now reload from encoded data message.reloadPersistence(encoded, null); Assert.assertEquals(AMQPMessage.MessageDataScanningStatus.RELOAD_PERSISTENCE, message.messageDataScanned()); assertTrue(message.hasScheduledDeliveryTime()); Assert.assertEquals(AMQPMessage.MessageDataScanningStatus.RELOAD_PERSISTENCE, message.messageDataScanned()); message.getHeader(); Assert.assertEquals(AMQPMessage.MessageDataScanningStatus.SCANNED, message.messageDataScanned()); assertTrue(message.hasScheduledDeliveryTime()); }
Example #28
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 #29
Source File: AmqpJmsStreamMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testNewMessageToSendDoesnNotContainMessageTypeAnnotation() throws Exception { AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createNewStreamMessageFacade(); MessageAnnotations annotations = amqpStreamMessageFacade.getMessageAnnotations(); assertNull("MessageAnnotations section was not present", annotations); assertEquals(JMS_STREAM_MESSAGE, amqpStreamMessageFacade.getJmsMsgType()); }
Example #30
Source File: MessageHelper.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Returns the value to which the specified key is mapped in the message annotations, or {@code null} if the message * annotations contain no mapping for the key. * * @param <T> the expected type of the property to read. * @param msg the message that contains the annotations. * @param key the name of the symbol to return a value for. * @param type the expected type of the value. * @return the annotation's value or {@code null} if no such annotation exists or its value is not of the expected * type. */ @SuppressWarnings("unchecked") public static <T> T getAnnotation(final Message msg, final String key, final Class<T> type) { final MessageAnnotations annotations = msg.getMessageAnnotations(); if (annotations == null) { return null; } else { final Object value = annotations.getValue().get(Symbol.getSymbol(key)); if (type.isInstance(value)) { return (T) value; } else { return null; } } }