Search in sources :

Example 16 with MessageAnnotations

use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method doTestConvertMessageWithJMSReplyTo.

private void doTestConvertMessageWithJMSReplyTo(ServerDestination jmsReplyTo, Object expectedAnnotationValue) throws Exception {
    ServerJMSTextMessage textMessage = createTextMessage();
    textMessage.setText("myTextMessageContent");
    textMessage.setJMSReplyTo(jmsReplyTo);
    Message amqp = AMQPConverter.getInstance().fromCore(textMessage.getInnerMessage()).getProtonMessage();
    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", jmsReplyTo.getAddress(), amqp.getReplyTo());
    }
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) Symbol(org.apache.qpid.proton.amqp.Symbol)

Example 17 with MessageAnnotations

use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.

the class MessageTransformationTest method testComplexQpidJMSMessageEncodeDecode.

@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);
    Message message = 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 = new AMQPMessage(message).toCore();
    Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
    assertEquals(10, outboudMessage.getApplicationProperties().getValue().size());
    assertEquals(4, outboudMessage.getMessageAnnotations().getValue().size());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.qpid.proton.message.Message) HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 18 with MessageAnnotations

use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.

the class AmqpMessage method lazyCreateMessageAnnotations.

private void lazyCreateMessageAnnotations() {
    if (messageAnnotationsMap == null) {
        messageAnnotationsMap = new HashMap<>();
        message.setMessageAnnotations(new MessageAnnotations(messageAnnotationsMap));
    }
}
Also used : MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations)

Example 19 with MessageAnnotations

use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.

the class JMSMappingInboundTransformerTest method doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl.

private void doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(Object replyToTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception {
    String replyToAddress = "replyToAddress";
    Message amqp = Message.Factory.create();
    amqp.setBody(new AmqpValue("myTextMessageContent"));
    amqp.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);
        amqp.setMessageAnnotations(ma);
    }
    javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(new AMQPMessage(amqp).toCore());
    assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage);
}
Also used : ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) TextMessage(javax.jms.TextMessage) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) TextMessage(javax.jms.TextMessage)

Example 20 with MessageAnnotations

use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.

the class JMSTransformationSpeedComparisonTest method createTypicalQpidJMSMessage.

private Message 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);
    Message message = 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;
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.qpid.proton.message.Message) HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue)

Aggregations

MessageAnnotations (org.apache.qpid.proton.amqp.messaging.MessageAnnotations)24 Symbol (org.apache.qpid.proton.amqp.Symbol)19 HashMap (java.util.HashMap)15 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)11 Message (org.apache.qpid.proton.message.Message)10 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)6 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)6 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)5 ServerJMSMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)5 Binary (org.apache.qpid.proton.amqp.Binary)5 Properties (org.apache.qpid.proton.amqp.messaging.Properties)5 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)4 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)4 ServerJMSObjectMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage)4 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)4 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)4 Section (org.apache.qpid.proton.amqp.messaging.Section)4 Map (java.util.Map)3 Data (org.apache.qpid.proton.amqp.messaging.Data)3 Header (org.apache.qpid.proton.amqp.messaging.Header)3