Search in sources :

Example 6 with ICoreMessage

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

the class TestConversions method testSimpleConversionMap.

@Test
public void testSimpleConversionMap() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    Map<String, Object> mapValues = new HashMap<>();
    mapValues.put("somestr", "value");
    mapValues.put("someint", Integer.valueOf(1));
    message.setBody(new AmqpValue(mapValues));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    serverMessage.getReadOnlyBodyBuffer();
    ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
    mapMessage.decode();
    verifyProperties(mapMessage);
    Assert.assertEquals(1, mapMessage.getInt("someint"));
    Assert.assertEquals("value", mapMessage.getString("somestr"));
    AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage());
    System.out.println(newAMQP.getProtonMessage().getBody());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 7 with ICoreMessage

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

the class TestConversions method testAmqpValueOfBooleanIsPassedThrough.

@Test
public void testAmqpValueOfBooleanIsPassedThrough() 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 AmqpValue(new Boolean(true)));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    verifyProperties(ServerJMSMessage.wrapCoreMessage(serverMessage));
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 8 with ICoreMessage

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

the class TestConversions method testSimpleConversionStream.

@Test
public void testSimpleConversionStream() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    List<Object> objects = new LinkedList<>();
    objects.add(new Integer(10));
    objects.add("10");
    message.setBody(new AmqpSequence(objects));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    ServerJMSStreamMessage streamMessage = (ServerJMSStreamMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
    verifyProperties(streamMessage);
    streamMessage.reset();
    assertEquals(10, streamMessage.readInt());
    assertEquals("10", streamMessage.readString());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with ICoreMessage

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

the class JMSMappingInboundTransformerTest method testCreateBytesMessageFromNoBodySectionAndContentType.

// ----- Null Body Section ------------------------------------------------//
/**
 * Test that a message with no body section, but with the content type set to
 * {@value AMQPMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromNoBodySectionAndContentType() throws Exception {
    Message message = Message.Factory.create();
    message.setContentType(AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE);
    AMQPMessage messageEncode = new AMQPMessage(message);
    ICoreMessage coreMessage = messageEncode.toCore();
    javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(coreMessage);
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) 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) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Test(org.junit.Test)

Example 10 with ICoreMessage

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

the class StompSession method sendMessage.

@Override
public int sendMessage(MessageReference ref, Message serverMessage, final ServerConsumer consumer, int deliveryCount) {
    ICoreMessage coreMessage = serverMessage.toCore();
    LargeServerMessageImpl largeMessage = null;
    ICoreMessage newServerMessage = serverMessage.toCore();
    try {
        StompSubscription subscription = subscriptions.get(consumer.getID());
        // subscription might be null if the consumer was closed
        if (subscription == null)
            return 0;
        StompFrame frame;
        ActiveMQBuffer buffer = coreMessage.getDataBuffer();
        frame = connection.createStompMessage(newServerMessage, buffer, subscription, deliveryCount);
        int length = frame.getEncodedSize();
        if (subscription.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) {
            if (manager.send(connection, frame)) {
                final long messageID = newServerMessage.getMessageID();
                final long consumerID = consumer.getID();
                // this will be called after the delivery is complete
                // we can't call session.ack within the delivery
                // as it could dead lock.
                afterDeliveryTasks.offer(new PendingTask() {

                    @Override
                    public void run() throws Exception {
                        // we ack and commit only if the send is successful
                        session.acknowledge(consumerID, messageID);
                        session.commit();
                    }
                });
            }
        } else {
            messagesToAck.put(newServerMessage.getMessageID(), new Pair<>(consumer.getID(), length));
            // Must send AFTER adding to messagesToAck - or could get acked from client BEFORE it's been added!
            manager.send(connection, frame);
        }
        return length;
    } catch (Exception e) {
        if (ActiveMQStompProtocolLogger.LOGGER.isDebugEnabled()) {
            ActiveMQStompProtocolLogger.LOGGER.debug(e);
        }
        return 0;
    } finally {
        if (largeMessage != null) {
            largeMessage.releaseResources();
            largeMessage = null;
        }
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) LargeServerMessageImpl(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl) PendingTask(org.apache.activemq.artemis.utils.PendingTask) 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