Search in sources :

Example 26 with ApplicationProperties

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

the class AMQPMessageTest method testApplicationPropertiesReencode.

@Test
public void testApplicationPropertiesReencode() {
    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);
    HashMap map = new HashMap();
    map.put("key", "string1");
    protonMessage.setApplicationProperties(new ApplicationProperties(map));
    AMQPMessage decoded = encodeAndDecodeMessage(protonMessage);
    assertEquals("someNiceLocal", decoded.getAddress());
    decoded.setAddress("newAddress");
    decoded.reencode();
    assertEquals(7, decoded.getHeader().getDeliveryCount().intValue());
    assertEquals(true, decoded.getHeader().getDurable());
    assertEquals("newAddress", decoded.getAddress());
    assertEquals("string1", decoded.getObjectProperty("key"));
    // validate if the message will be the same after delivery
    AMQPMessage newDecoded = encodeDelivery(decoded, 3);
    assertEquals(2, decoded.getHeader().getDeliveryCount().intValue());
    assertEquals(true, newDecoded.getHeader().getDurable());
    assertEquals("newAddress", newDecoded.getAddress());
    assertEquals("string1", newDecoded.getObjectProperty("key"));
}
Also used : Header(org.apache.qpid.proton.amqp.messaging.Header) HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Test(org.junit.Test)

Example 27 with ApplicationProperties

use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties 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 28 with ApplicationProperties

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

the class TestConversions method testSimpleConversionBytes.

@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 = new AMQPMessage(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);
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Data(org.apache.qpid.proton.amqp.messaging.Data) Binary(org.apache.qpid.proton.amqp.Binary) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Test(org.junit.Test)

Example 29 with ApplicationProperties

use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties 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)

Example 30 with ApplicationProperties

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

the class AMQPMessage method initalizeObjects.

private void initalizeObjects() {
    if (protonMessage == null) {
        if (data == null) {
            headerEnds = 0;
            messagePaylodStart = 0;
            _header = new Header();
            _deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
            _properties = new Properties();
            applicationProperties = new ApplicationProperties(new HashMap<>());
            protonMessage = (MessageImpl) Message.Factory.create();
            protonMessage.setApplicationProperties(applicationProperties);
            protonMessage.setDeliveryAnnotations(_deliveryAnnotations);
        }
    }
}
Also used : Header(org.apache.qpid.proton.amqp.messaging.Header) HashMap(java.util.HashMap) DeliveryAnnotations(org.apache.qpid.proton.amqp.messaging.DeliveryAnnotations) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties)

Aggregations

ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)41 HashMap (java.util.HashMap)25 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)14 Properties (org.apache.qpid.proton.amqp.messaging.Properties)12 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)11 Message (org.apache.qpid.proton.message.Message)11 Binary (org.apache.qpid.proton.amqp.Binary)10 MessageAnnotations (org.apache.qpid.proton.amqp.messaging.MessageAnnotations)10 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)9 Test (org.junit.Test)9 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)8 Data (org.apache.qpid.proton.amqp.messaging.Data)8 Symbol (org.apache.qpid.proton.amqp.Symbol)7 Section (org.apache.qpid.proton.amqp.messaging.Section)7 Map (java.util.Map)6 Header (org.apache.qpid.proton.amqp.messaging.Header)6 Test (org.junit.jupiter.api.Test)5 Buffer (io.vertx.core.buffer.Buffer)3 JsonObject (io.vertx.core.json.JsonObject)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3