Search in sources :

Example 6 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class CoreMessageTest method testGenerateEmpty.

@Test
public void testGenerateEmpty() {
    CoreMessage empty = new CoreMessage().initBuffer(100);
    ByteBuf buffer = Unpooled.buffer(200);
    empty.sendBuffer(buffer, 0);
    CoreMessage empty2 = new CoreMessage();
    empty2.receiveBuffer(buffer);
    try {
        empty2.getBodyBuffer().readLong();
        Assert.fail("should throw exception");
    } catch (Exception expected) {
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Test(org.junit.Test)

Example 7 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class CoreMessageTest method testSaveReceiveLimitedBytes.

@Test
public void testSaveReceiveLimitedBytes() {
    CoreMessage empty = new CoreMessage().initBuffer(100);
    System.out.println("R " + empty.getBodyBuffer().readerIndex() + " W " + empty.getBodyBuffer().writerIndex());
    empty.getBodyBuffer().writeByte((byte) 7);
    System.out.println("R " + empty.getBodyBuffer().readerIndex() + " W " + empty.getBodyBuffer().writerIndex());
    ByteBuf buffer = Unpooled.buffer(200);
    empty.sendBuffer(buffer, 0);
    CoreMessage empty2 = new CoreMessage();
    empty2.receiveBuffer(buffer);
    Assert.assertEquals((byte) 7, empty2.getBodyBuffer().readByte());
    System.out.println("Readable :: " + empty2.getBodyBuffer().readerIndex() + " writer :" + empty2.getBodyBuffer().writerIndex());
    try {
        empty2.getBodyBuffer().readByte();
        Assert.fail("should throw exception");
    } catch (Exception expected) {
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Test(org.junit.Test)

Example 8 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class CoreMessageTest method decodeMessage.

private CoreMessage decodeMessage() {
    ByteBuf newBuffer = Unpooled.buffer(BYTE_ENCODE.capacity());
    newBuffer.writeBytes(BYTE_ENCODE, 0, BYTE_ENCODE.writerIndex());
    CoreMessage coreMessage = internalDecode(newBuffer);
    int encodeSize = coreMessage.getEncodeSize();
    Assert.assertEquals(newBuffer.capacity(), encodeSize);
    Assert.assertEquals(ADDRESS, coreMessage.getAddressSimpleString());
    Assert.assertEquals(PROP1_VALUE.toString(), coreMessage.getStringProperty(PROP1_NAME));
    ByteBuf destinedBuffer = Unpooled.buffer(BYTE_ENCODE.array().length);
    coreMessage.sendBuffer(destinedBuffer, 0);
    byte[] destinedArray = destinedBuffer.array();
    byte[] sourceArray = BYTE_ENCODE.array();
    CoreMessage newDecoded = internalDecode(Unpooled.wrappedBuffer(destinedArray));
    Assert.assertEquals(encodeSize, newDecoded.getEncodeSize());
    Assert.assertArrayEquals(sourceArray, destinedArray);
    return coreMessage;
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 9 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class AddressControlImpl method sendMessage.

@Override
public String sendMessage(final Map<String, String> headers, final int type, final String body, boolean durable, final String user, final String password) throws Exception {
    try {
        securityStore.check(addressInfo.getName(), CheckType.SEND, new SecurityAuth() {

            @Override
            public String getUsername() {
                return user;
            }

            @Override
            public String getPassword() {
                return password;
            }

            @Override
            public RemotingConnection getRemotingConnection() {
                return null;
            }
        });
        CoreMessage message = new CoreMessage(storageManager.generateID(), 50);
        if (headers != null) {
            for (String header : headers.keySet()) {
                message.putStringProperty(new SimpleString(header), new SimpleString(headers.get(header)));
            }
        }
        message.setType((byte) type);
        message.setDurable(durable);
        message.setTimestamp(System.currentTimeMillis());
        if (body != null) {
            if (type == Message.TEXT_TYPE) {
                message.getBodyBuffer().writeNullableSimpleString(new SimpleString(body));
            } else {
                message.getBodyBuffer().writeBytes(Base64.decode(body));
            }
        }
        message.setAddress(addressInfo.getName());
        postOffice.route(message, true);
        return "" + message.getMessageID();
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 10 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class QueueControlImpl method sendMessage.

@Override
public String sendMessage(final Map<String, String> headers, final int type, final String body, boolean durable, final String user, final String password) throws Exception {
    try {
        securityStore.check(queue.getAddress(), queue.getName(), CheckType.SEND, new SecurityAuth() {

            @Override
            public String getUsername() {
                return user;
            }

            @Override
            public String getPassword() {
                return password;
            }

            @Override
            public RemotingConnection getRemotingConnection() {
                return null;
            }
        });
        CoreMessage message = new CoreMessage(storageManager.generateID(), 50);
        if (headers != null) {
            for (String header : headers.keySet()) {
                message.putStringProperty(new SimpleString(header), new SimpleString(headers.get(header)));
            }
        }
        message.setType((byte) type);
        message.setDurable(durable);
        message.setTimestamp(System.currentTimeMillis());
        if (body != null) {
            if (type == Message.TEXT_TYPE) {
                message.getBodyBuffer().writeNullableSimpleString(new SimpleString(body));
            } else {
                message.getBodyBuffer().writeBytes(Base64.decode(body));
            }
        }
        message.setAddress(queue.getAddress());
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putLong(queue.getID());
        message.putBytesProperty(Message.HDR_ROUTE_TO_IDS, buffer.array());
        postOffice.route(message, true);
        return "" + message.getMessageID();
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteBuffer(java.nio.ByteBuffer) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Aggregations

CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)48 Test (org.junit.Test)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)16 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 Message (org.apache.activemq.artemis.api.core.Message)11 Configuration (org.apache.activemq.artemis.core.config.Configuration)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 ByteBuf (io.netty.buffer.ByteBuf)5 LinkedList (java.util.LinkedList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)3 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)3 RoutingContext (org.apache.activemq.artemis.core.server.RoutingContext)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)2 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)2