Search in sources :

Example 21 with ICoreMessage

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

the class ClientProducerImpl method doSend.

private void doSend(SimpleString sendingAddress, final Message msgToSend, final SendAcknowledgementHandler handler) throws ActiveMQException {
    if (sendingAddress == null) {
        sendingAddress = this.address;
    }
    session.startCall();
    try {
        // In case we received message from another protocol, we first need to convert it to core as the ClientProducer only understands core
        ICoreMessage msg = msgToSend.toCore();
        ClientProducerCredits theCredits;
        boolean isLarge;
        // server's on which case we can't' convert the message into large at the servers
        if (sessionContext.supportsLargeMessage() && (getBodyInputStream(msg) != null || msg.isLargeMessage() || msg.getBodyBuffer().writerIndex() > minLargeMessageSize)) {
            isLarge = true;
        } else {
            isLarge = false;
        }
        if (!isLarge) {
            session.setAddress(msg, sendingAddress);
        } else {
            msg.setAddress(sendingAddress);
        }
        // Anonymous
        theCredits = session.getCredits(sendingAddress, true);
        if (rateLimiter != null) {
            // Rate flow control
            rateLimiter.limit();
        }
        if (groupID != null) {
            msg.putStringProperty(Message.HDR_GROUP_ID, groupID);
        }
        final boolean sendBlockingConfig = msg.isDurable() ? blockOnDurableSend : blockOnNonDurableSend;
        // if Handler != null, we will send non blocking
        final boolean sendBlocking = sendBlockingConfig && handler == null;
        session.workDone();
        if (isLarge) {
            largeMessageSend(sendBlocking, msg, theCredits, handler);
        } else {
            sendRegularMessage(sendingAddress, msg, sendBlocking, theCredits, handler);
        }
    } finally {
        session.endCall();
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage)

Example 22 with ICoreMessage

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

the class MessageImplTest method getSetAttributes.

@Test
public void getSetAttributes() {
    for (int j = 0; j < 10; j++) {
        byte[] bytes = new byte[1000];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = RandomUtil.randomByte();
        }
        final byte type = RandomUtil.randomByte();
        final boolean durable = RandomUtil.randomBoolean();
        final long expiration = RandomUtil.randomLong();
        final long timestamp = RandomUtil.randomLong();
        final byte priority = RandomUtil.randomByte();
        ICoreMessage message1 = new ClientMessageImpl(type, durable, expiration, timestamp, priority, 100);
        ICoreMessage message = message1;
        Assert.assertEquals(type, message.getType());
        Assert.assertEquals(durable, message.isDurable());
        Assert.assertEquals(expiration, message.getExpiration());
        Assert.assertEquals(timestamp, message.getTimestamp());
        Assert.assertEquals(priority, message.getPriority());
        final SimpleString destination = new SimpleString(RandomUtil.randomString());
        final boolean durable2 = RandomUtil.randomBoolean();
        final long expiration2 = RandomUtil.randomLong();
        final long timestamp2 = RandomUtil.randomLong();
        final byte priority2 = RandomUtil.randomByte();
        message.setAddress(destination);
        Assert.assertEquals(destination, message.getAddressSimpleString());
        message.setDurable(durable2);
        Assert.assertEquals(durable2, message.isDurable());
        message.setExpiration(expiration2);
        Assert.assertEquals(expiration2, message.getExpiration());
        message.setTimestamp(timestamp2);
        Assert.assertEquals(timestamp2, message.getTimestamp());
        message.setPriority(priority2);
        Assert.assertEquals(priority2, message.getPriority());
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) Test(org.junit.Test)

Example 23 with ICoreMessage

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

the class PagingManagerImplTest method testPagingManager.

@Test
public void testPagingManager() throws Exception {
    HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
    addressSettings.setDefault(new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE));
    final StorageManager storageManager = new NullStorageManager();
    PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null);
    PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings);
    managerImpl.start();
    PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
    ICoreMessage msg = createMessage(1L, new SimpleString("simple-test"), createRandomBuffer(10));
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    store.startPaging();
    Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    Page page = store.depage();
    page.open();
    List<PagedMessage> msgs = page.read(new NullStorageManager());
    page.close();
    Assert.assertEquals(1, msgs.size());
    ActiveMQTestBase.assertEqualsByteArrays(msg.getBodyBuffer().writerIndex(), msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage()).toCore().getBodyBuffer().toByteBuffer().array());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Test(org.junit.Test)

Example 24 with ICoreMessage

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

the class MQTTUtil method createServerMessage.

private static ICoreMessage createServerMessage(MQTTSession session, SimpleString address, boolean retain, int qos) {
    long id = session.getServer().getStorageManager().generateID();
    CoreMessage message = new CoreMessage(id, DEFAULT_SERVER_MESSAGE_BUFFER_SIZE, session.getCoreMessageObjectPools());
    message.setAddress(address);
    message.putBooleanProperty(MQTT_MESSAGE_RETAIN_KEY, retain);
    message.putIntProperty(MQTT_QOS_LEVEL_KEY, qos);
    message.setType(Message.BYTES_TYPE);
    return message;
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage)

Example 25 with ICoreMessage

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

the class MessageTransformationTest method testHeaderButNoPropertiesEncodeDecode.

@Test
public void testHeaderButNoPropertiesEncodeDecode() throws Exception {
    Message incomingMessage = Proton.message();
    incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
    incomingMessage.setDurable(true);
    ICoreMessage core = new AMQPMessage(incomingMessage).toCore();
    Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
}
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)

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