Search in sources :

Example 31 with ICoreMessage

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

the class ConversionTest method testCoreToJMSConversion.

@Test
public void testCoreToJMSConversion() {
    ICoreMessage clientMessage = new ClientMessageImpl();
    clientMessage.setDurable(true).setPriority((byte) 9).setExpiration(123456);
    Map<String, Object> messageMap = clientMessage.toMap();
    Map<String, Object> jmsMap = ActiveMQMessage.coreMaptoJMSMap(messageMap);
    Object priority = jmsMap.get("JMSPriority");
    assertTrue(priority instanceof Integer);
    assertEquals(9, priority);
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) Test(org.junit.Test)

Example 32 with ICoreMessage

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

the class ServerSessionImpl method messageToLargeMessage.

private LargeServerMessage messageToLargeMessage(Message message) throws Exception {
    ICoreMessage coreMessage = message.toCore();
    LargeServerMessage lsm = getStorageManager().createLargeMessage(storageManager.generateID(), coreMessage);
    ActiveMQBuffer buffer = coreMessage.getReadOnlyBodyBuffer();
    byte[] body = new byte[buffer.readableBytes()];
    buffer.readBytes(body);
    lsm.addBytes(body);
    lsm.releaseResources();
    lsm.putLongProperty(Message.HDR_LARGE_BODY_SIZE, body.length);
    return lsm;
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 33 with ICoreMessage

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

the class ManagementServiceImplTest method testHandleManagementMessageWithUnknownAttribute.

@Test
public void testHandleManagementMessageWithUnknownAttribute() throws Exception {
    Configuration config = createBasicConfig().setJMXManagementEnabled(false);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    // invoke attribute and operation on the server
    ICoreMessage message = new CoreMessage(1, 100);
    ManagementHelper.putAttribute(message, ResourceNames.BROKER, "started");
    ICoreMessage reply = server.getManagementService().handleMessage(message);
    Assert.assertTrue(ManagementHelper.hasOperationSucceeded(reply));
    Assert.assertTrue((Boolean) ManagementHelper.getResult(reply));
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Configuration(org.apache.activemq.artemis.core.config.Configuration) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Test(org.junit.Test)

Example 34 with ICoreMessage

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

the class ActiveMQTestBase method generateMessage.

protected Message generateMessage(final long id) {
    ICoreMessage message = new CoreMessage(id, 1000);
    message.setMessageID(id);
    message.getBodyBuffer().writeString(UUID.randomUUID().toString());
    message.setAddress(new SimpleString("foo"));
    return message;
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 35 with ICoreMessage

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

the class CoreAmqpConverter method convertBody.

private static Section convertBody(ServerJMSMessage message, Map<Symbol, Object> maMap, Properties properties) throws JMSException {
    Section body = null;
    if (message instanceof ServerJMSBytesMessage) {
        Binary payload = getBinaryFromMessageBody((ServerJMSBytesMessage) message);
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_BYTES_MESSAGE);
        if (payload == null) {
            payload = EMPTY_BINARY;
        } else {
            body = new AmqpValue(payload);
        }
    } else if (message instanceof ServerJMSTextMessage) {
        body = new AmqpValue(((TextMessage) message).getText());
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_TEXT_MESSAGE);
    } else if (message instanceof ServerJMSMapMessage) {
        body = new AmqpValue(getMapFromMessageBody((ServerJMSMapMessage) message));
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MAP_MESSAGE);
    } else if (message instanceof ServerJMSStreamMessage) {
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_STREAM_MESSAGE);
        ArrayList<Object> list = new ArrayList<>();
        final ServerJMSStreamMessage m = (ServerJMSStreamMessage) message;
        try {
            while (true) {
                list.add(m.readObject());
            }
        } catch (MessageEOFException e) {
        }
        body = new AmqpSequence(list);
    } else if (message instanceof ServerJMSObjectMessage) {
        properties.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE);
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_OBJECT_MESSAGE);
        Binary payload = getBinaryFromMessageBody((ServerJMSObjectMessage) message);
        if (payload == null) {
            payload = EMPTY_BINARY;
        }
        body = new Data(payload);
        // we are sending it.
        if (!message.propertyExists(JMS_AMQP_CONTENT_TYPE)) {
            message.setStringProperty(JMS_AMQP_CONTENT_TYPE, SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());
        }
    } else if (message instanceof ServerJMSMessage) {
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MESSAGE);
        // If this is not an AMQP message that was converted then the original encoding
        // will be unknown so we check for special cases of messages with special data
        // encoded into the server message body.
        ICoreMessage internalMessage = message.getInnerMessage();
        int readerIndex = internalMessage.getBodyBuffer().readerIndex();
        try {
            Object s = internalMessage.getBodyBuffer().readNullableSimpleString();
            if (s != null) {
                body = new AmqpValue(s.toString());
            }
        } catch (Throwable ignored) {
            logger.debug("Exception ignored during conversion", ignored.getMessage(), ignored);
            body = new AmqpValue("Conversion to AMQP error!");
        } finally {
            internalMessage.getBodyBuffer().readerIndex(readerIndex);
        }
    }
    return body;
}
Also used : MessageEOFException(javax.jms.MessageEOFException) ArrayList(java.util.ArrayList) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) Data(org.apache.qpid.proton.amqp.messaging.Data) Section(org.apache.qpid.proton.amqp.messaging.Section) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Binary(org.apache.qpid.proton.amqp.Binary) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)

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