Search in sources :

Example 1 with ICoreMessage

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

the class OpenTypeSupport method convert.

public static CompositeData convert(MessageReference ref) throws OpenDataException {
    CompositeType ct;
    ICoreMessage message = ref.getMessage().toCore();
    Map<String, Object> fields;
    byte type = message.getType();
    switch(type) {
        case Message.TEXT_TYPE:
            ct = TEXT_FACTORY.getCompositeType();
            fields = TEXT_FACTORY.getFields(ref);
            break;
        default:
            ct = BYTES_FACTORY.getCompositeType();
            fields = BYTES_FACTORY.getFields(ref);
            break;
    }
    return new CompositeDataSupport(ct, fields);
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CompositeType(javax.management.openmbean.CompositeType)

Example 2 with ICoreMessage

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

the class Page method delete.

public boolean delete(final PagedMessage[] messages) throws Exception {
    if (storageManager != null) {
        storageManager.pageDeleted(storeName, pageId);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Deleting pageNr=" + pageId + " on store " + storeName);
    }
    if (messages != null) {
        for (PagedMessage msg : messages) {
            if (msg.getMessage() instanceof ICoreMessage && (msg.getMessage()).isLargeMessage()) {
                LargeServerMessage lmsg = (LargeServerMessage) msg.getMessage();
                // Remember, cannot call delete directly here
                // Because the large-message may be linked to another message
                // or it may still being delivered even though it has been acked already
                lmsg.decrementDelayDeletionCount();
            }
        }
    }
    try {
        if (suspiciousRecords) {
            ActiveMQServerLogger.LOGGER.pageInvalid(file.getFileName(), file.getFileName());
            file.renameTo(file.getFileName() + ".invalidPage");
        } else {
            file.delete();
        }
        return true;
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.pageDeleteError(e);
        return false;
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) IOException(java.io.IOException)

Example 3 with ICoreMessage

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

the class MQTTUtil method createServerMessageFromByteBuf.

public static Message createServerMessageFromByteBuf(MQTTSession session, String topic, boolean retain, int qos, ByteBuf payload) {
    String coreAddress = convertMQTTAddressFilterToCore(topic, session.getWildcardConfiguration());
    SimpleString address = SimpleString.toSimpleString(coreAddress, session.getCoreMessageObjectPools().getAddressStringSimpleStringPool());
    ICoreMessage message = createServerMessage(session, address, retain, qos);
    message.getBodyBuffer().writeBytes(payload, 0, payload.readableBytes());
    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)

Example 4 with ICoreMessage

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

the class AMQPMessageTest method testExtraProperty.

@Test
public void testExtraProperty() {
    MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
    byte[] original = RandomUtil.randomBytes();
    SimpleString name = SimpleString.toSimpleString("myProperty");
    AMQPMessage decoded = encodeAndDecodeMessage(protonMessage);
    decoded.setAddress("someAddress");
    decoded.setMessageID(33);
    decoded.putExtraBytesProperty(name, original);
    ICoreMessage coreMessage = decoded.toCore();
    Assert.assertEquals(original, coreMessage.getBytesProperty(name));
    ActiveMQBuffer buffer = ActiveMQBuffers.pooledBuffer(10 * 1024);
    try {
        decoded.getPersister().encode(buffer, decoded);
        // the journal reader will read 1 byte to find the persister
        Assert.assertEquals(AMQPMessagePersisterV2.getInstance().getID(), buffer.readByte());
        AMQPMessage readMessage = (AMQPMessage) decoded.getPersister().decode(buffer, null);
        Assert.assertEquals(33, readMessage.getMessageID());
        Assert.assertEquals("someAddress", readMessage.getAddress());
        Assert.assertArrayEquals(original, readMessage.getExtraBytesProperty(name));
    } finally {
        buffer.release();
    }
    {
        ICoreMessage embeddedMessage = EmbedMessageUtil.embedAsCoreMessage(decoded);
        AMQPMessage readMessage = (AMQPMessage) EmbedMessageUtil.extractEmbedded(embeddedMessage);
        Assert.assertEquals(33, readMessage.getMessageID());
        Assert.assertEquals("someAddress", readMessage.getAddress());
        Assert.assertArrayEquals(original, readMessage.getExtraBytesProperty(name));
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 5 with ICoreMessage

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

the class TestConversions method testSimpleConversionText.

@Test
public void testSimpleConversionText() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    String text = "someText";
    message.setBody(new AmqpValue(text));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    ServerJMSTextMessage textMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
    textMessage.decode();
    verifyProperties(textMessage);
    Assert.assertEquals(text, textMessage.getText());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) 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)

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