Search in sources :

Example 26 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.

the class MessageTransformationTest method testPropertiesButNoHeadersEncodeDecode.

@Test
public void testPropertiesButNoHeadersEncodeDecode() throws Exception {
    Message incomingMessage = Proton.message();
    incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
    incomingMessage.setMessageId("ID:SomeQualifier:0:0:1");
    ICoreMessage core = new AMQPMessage(incomingMessage).toCore();
    Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
    assertNull(outboudMessage.getHeader());
    assertNotNull(outboudMessage.getProperties());
}
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) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 27 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.

the class MessageTransformationTest method testBodyOnlyEncodeDecode.

@Test
public void testBodyOnlyEncodeDecode() throws Exception {
    Message incomingMessage = Proton.message();
    incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
    ICoreMessage core = new AMQPMessage(incomingMessage).toCore();
    Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
    assertNull(outboudMessage.getHeader());
}
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) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 28 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage 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 29 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.

the class EmbedMessageUtil method embedAsCoreMessage.

public static ICoreMessage embedAsCoreMessage(Message source) {
    if (source instanceof ICoreMessage) {
        return (ICoreMessage) source;
    } else {
        Persister persister = source.getPersister();
        CoreMessage message = new CoreMessage(source.getMessageID(), persister.getEncodeSize(source) + signature.length + CoreMessage.BODY_OFFSET).setType(Message.EMBEDDED_TYPE);
        ActiveMQBuffer buffer = message.getBodyBuffer();
        buffer.writeBytes(signature);
        persister.encode(buffer, source);
        return message;
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Persister(org.apache.activemq.artemis.core.persistence.Persister) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 30 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.

the class SimpleTransformer method transform.

@Override
public Message transform(final Message messageParameter) {
    ICoreMessage message = messageParameter.toCore();
    SimpleString oldProp = (SimpleString) message.getObjectProperty(new SimpleString("wibble"));
    if (!oldProp.equals(new SimpleString("bing"))) {
        throw new IllegalStateException("Wrong property value!!");
    }
    // Change a property
    message.putStringProperty(new SimpleString("wibble"), new SimpleString("bong"));
    // Change the body
    ActiveMQBuffer buffer = message.getBodyBuffer();
    buffer.readerIndex(0);
    String str = buffer.readString();
    if (!str.equals("doo be doo be doo be doo")) {
        throw new IllegalStateException("Wrong body!!");
    }
    buffer.clear();
    buffer.writeString("dee be dee be dee be dee");
    return message;
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)39 Test (org.junit.Test)24 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)17 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)10 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 Message (org.apache.qpid.proton.message.Message)7 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)6 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)6 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)4 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)4 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)3 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)3 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)3 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)3 HashMap (java.util.HashMap)2 ClientMessageImpl (org.apache.activemq.artemis.core.client.impl.ClientMessageImpl)2 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)2 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)2