Search in sources :

Example 31 with CoreMessage

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

the class CoreMessageTest method sendThroughPacketsClient.

/**
 * The message is received, then sent to the other side untouched
 */
@Test
public void sendThroughPacketsClient() {
    CoreMessage decodedMessage = decodeMessage();
    int encodeSize = decodedMessage.getEncodeSize();
    Assert.assertEquals(BYTE_ENCODE.capacity(), encodeSize);
    SessionReceiveMessage sendMessage = new SessionReceiveMessage(33, decodedMessage, 7);
    sendMessage.setChannelID(777);
    ActiveMQBuffer buffer = sendMessage.encode(null);
    buffer.readerIndex(5);
    SessionReceiveMessage sendMessageReceivedSent = new SessionReceiveMessage(new CoreMessage());
    sendMessageReceivedSent.decode(buffer);
    Assert.assertEquals(33, sendMessageReceivedSent.getConsumerID());
    Assert.assertEquals(7, sendMessageReceivedSent.getDeliveryCount());
    Assert.assertEquals(encodeSize, sendMessageReceivedSent.getMessage().getEncodeSize());
    Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(sendMessageReceivedSent.getMessage().getReadOnlyBodyBuffer()).toString());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) SessionReceiveMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 32 with CoreMessage

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

the class CoreMessageTest method sendThroughPackets.

/**
 * The message is received, then sent to the other side untouched
 */
@Test
public void sendThroughPackets() {
    CoreMessage decodedMessage = decodeMessage();
    int encodeSize = decodedMessage.getEncodeSize();
    Assert.assertEquals(BYTE_ENCODE.capacity(), encodeSize);
    SessionSendMessage sendMessage = new SessionSendMessage(decodedMessage, true, null);
    sendMessage.setChannelID(777);
    ActiveMQBuffer buffer = sendMessage.encode(null);
    byte[] byteArray = buffer.byteBuf().array();
    System.out.println("Sending " + ByteUtil.bytesToHex(buffer.toByteBuffer().array(), 1) + ", bytes = " + byteArray.length);
    buffer.readerIndex(5);
    SessionSendMessage sendMessageReceivedSent = new SessionSendMessage(new CoreMessage());
    sendMessageReceivedSent.decode(buffer);
    Assert.assertEquals(encodeSize, sendMessageReceivedSent.getMessage().getEncodeSize());
    Assert.assertTrue(sendMessageReceivedSent.isRequiresResponse());
    Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(sendMessageReceivedSent.getMessage().getReadOnlyBodyBuffer()).toString());
}
Also used : SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 33 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage 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 34 with CoreMessage

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

the class VersionedStompFrameHandler method onSend.

public StompFrame onSend(StompFrame frame) {
    StompFrame response = null;
    try {
        connection.validate();
        String destination = getDestination(frame);
        RoutingType routingType = getRoutingType(frame.getHeader(Headers.Send.DESTINATION_TYPE), frame.getHeader(Headers.Send.DESTINATION));
        connection.autoCreateDestinationIfPossible(destination, routingType);
        connection.checkDestination(destination);
        connection.checkRoutingSemantics(destination, routingType);
        String txID = frame.getHeader(Stomp.Headers.TRANSACTION);
        long timestamp = System.currentTimeMillis();
        CoreMessage message = connection.createServerMessage();
        if (routingType != null) {
            message.setRoutingType(routingType);
        }
        message.setTimestamp(timestamp);
        message.setAddress(SimpleString.toSimpleString(destination));
        StompUtils.copyStandardHeadersFromFrameToMessage(frame, message);
        if (frame.hasHeader(Stomp.Headers.CONTENT_LENGTH)) {
            message.setType(Message.BYTES_TYPE);
            message.getBodyBuffer().writeBytes(frame.getBodyAsBytes());
        } else {
            message.setType(Message.TEXT_TYPE);
            String text = frame.getBody();
            message.getBodyBuffer().writeNullableSimpleString(SimpleString.toSimpleString(text));
        }
        connection.sendServerMessage(message, txID);
    } catch (ActiveMQStompException e) {
        response = e.getFrame();
    } catch (Exception e) {
        ActiveMQStompException error = BUNDLE.errorHandleSend(e).setHandler(this);
        response = error.getFrame();
    }
    return response;
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 35 with CoreMessage

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

the class ReplicationTest method testSendPackets.

@Test
public void testSendPackets() throws Exception {
    setupServer(true);
    JournalStorageManager storage = getStorage();
    manager = liveServer.getReplicationManager();
    waitForComponent(manager);
    Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
    replicatedJournal.appendPrepareRecord(1, new FakeData(), false);
    replicatedJournal.appendAddRecord(1, (byte) 1, new FakeData(), false);
    replicatedJournal.appendUpdateRecord(1, (byte) 2, new FakeData(), false);
    replicatedJournal.appendDeleteRecord(1, false);
    replicatedJournal.appendAddRecordTransactional(2, 2, (byte) 1, new FakeData());
    replicatedJournal.appendUpdateRecordTransactional(2, 2, (byte) 2, new FakeData());
    replicatedJournal.appendCommitRecord(2, false);
    replicatedJournal.appendDeleteRecordTransactional(3, 4, new FakeData());
    replicatedJournal.appendPrepareRecord(3, new FakeData(), false);
    replicatedJournal.appendRollbackRecord(3, false);
    blockOnReplication(storage, manager);
    Assert.assertTrue("Expecting no active tokens:" + manager.getActiveTokens(), manager.getActiveTokens().isEmpty());
    CoreMessage msg = new CoreMessage().initBuffer(1024).setMessageID(1);
    SimpleString dummy = new SimpleString("dummy");
    msg.setAddress(dummy);
    replicatedJournal.appendAddRecordTransactional(23, 24, (byte) 1, new FakeData());
    PagedMessage pgmsg = new PagedMessageImpl(msg, new long[0]);
    manager.pageWrite(pgmsg, 1);
    manager.pageWrite(pgmsg, 2);
    manager.pageWrite(pgmsg, 3);
    manager.pageWrite(pgmsg, 4);
    blockOnReplication(storage, manager);
    PagingManager pagingManager = createPageManager(backupServer.getStorageManager(), backupServer.getConfiguration(), backupServer.getExecutorFactory(), backupServer.getAddressSettingsRepository());
    PagingStore store = pagingManager.getPageStore(dummy);
    store.start();
    Assert.assertEquals(4, store.getNumberOfPages());
    store.stop();
    manager.pageDeleted(dummy, 1);
    manager.pageDeleted(dummy, 2);
    manager.pageDeleted(dummy, 3);
    manager.pageDeleted(dummy, 4);
    manager.pageDeleted(dummy, 5);
    manager.pageDeleted(dummy, 6);
    blockOnReplication(storage, manager);
    CoreMessage serverMsg = new CoreMessage();
    serverMsg.setMessageID(500);
    serverMsg.setAddress(new SimpleString("tttt"));
    ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(100);
    serverMsg.encodeHeadersAndProperties(buffer.byteBuf());
    manager.largeMessageBegin(500);
    manager.largeMessageWrite(500, new byte[1024]);
    manager.largeMessageDelete(Long.valueOf(500), storage);
    blockOnReplication(storage, manager);
    store.start();
    Assert.assertEquals(0, store.getNumberOfPages());
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) PagedMessageImpl(org.apache.activemq.artemis.core.paging.impl.PagedMessageImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

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