Search in sources :

Example 26 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompWithLargeMessagesTest method testSendReceiveLargeMessage.

@Test
public void testSendReceiveLargeMessage() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    try {
        String address = "testLargeMessageAddress";
        server.getActiveMQServer().createQueue(SimpleString.toSimpleString(address), RoutingType.ANYCAST, SimpleString.toSimpleString(address), null, true, false);
        // STOMP default is UTF-8 == 1 byte per char.
        // 10MB
        int largeMessageStringSize = 10 * 1024 * 1024;
        StringBuilder b = new StringBuilder(largeMessageStringSize);
        for (int i = 0; i < largeMessageStringSize; i++) {
            b.append('t');
        }
        String payload = b.toString();
        // Set up STOMP subscription
        conn.connect(defUser, defPass);
        subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO, null, null, address, true);
        // Send Large Message
        System.out.println("Sending Message Size: " + largeMessageStringSize);
        send(conn, address, null, payload);
        // Receive STOMP Message
        ClientStompFrame frame = conn.receiveFrame();
        System.out.println(frame.getBody().length());
        assertTrue(frame.getBody().equals(payload));
    } finally {
        conn.disconnect();
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 27 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompWithLargeMessagesTest method testReceiveLargeCompressedToRegularPersistentMessagesFromCore.

// //stomp v12 sender -> large -> stomp v12 receiver
// @Test
// public void testSendReceiveLargePersistentMessagesV12() throws Exception {
// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", "localhost", port);
// connV12.connect(defUser, defPass);
// 
// int count = 10;
// int szBody = 1024 * 1024;
// char[] contents = new char[szBody];
// for (int i = 0; i < szBody; i++) {
// contents[i] = 'A';
// }
// String body = new String(contents);
// 
// ClientStompFrame frame = connV12.createFrame("SEND");
// frame.addHeader("destination-type", "ANYCAST");
// frame.addHeader("destination", getQueuePrefix() + getQueueName());
// frame.addHeader("persistent", "true");
// frame.setBody(body);
// 
// for (int i = 0; i < count; i++) {
// connV12.sendFrame(frame);
// }
// 
// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
// subFrame.addHeader("id", "a-sub");
// subFrame.addHeader("subscription-type", "ANYCAST");
// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
// subFrame.addHeader("ack", "auto");
// 
// connV12.sendFrame(subFrame);
// 
// for (int i = 0; i < count; i++) {
// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
// 
// Assert.assertNotNull(receiveFrame);
// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
// assertEquals(szBody, receiveFrame.getBody().length());
// }
// 
// // remove susbcription
// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
// unsubFrame.addHeader("id", "a-sub");
// connV12.sendFrame(unsubFrame);
// 
// connV12.disconnect();
// }
// 
// //core sender -> large -> stomp v12 receiver
// @Test
// public void testReceiveLargePersistentMessagesFromCoreV12() throws Exception {
// int msgSize = 3 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
// char[] contents = new char[msgSize];
// for (int i = 0; i < msgSize; i++) {
// contents[i] = 'B';
// }
// String msg = new String(contents);
// 
// int count = 10;
// for (int i = 0; i < count; i++) {
// this.sendJmsMessage(msg);
// }
// 
// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", "localhost", port);
// connV12.connect(defUser, defPass);
// 
// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
// subFrame.addHeader("id", "a-sub");
// subFrame.addHeader("subscription-type", "ANYCAST");
// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
// subFrame.addHeader("ack", "auto");
// connV12.sendFrame(subFrame);
// 
// for (int i = 0; i < count; i++) {
// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
// 
// Assert.assertNotNull(receiveFrame);
// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
// assertEquals(msgSize, receiveFrame.getBody().length());
// }
// 
// // remove susbcription
// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
// unsubFrame.addHeader("id", "a-sub");
// connV12.sendFrame(unsubFrame);
// 
// connV12.disconnect();
// }
// core sender -> large (compressed regular) -> stomp v10 receiver
@Test
public void testReceiveLargeCompressedToRegularPersistentMessagesFromCore() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass);
    LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
    LargeMessageTestBase.adjustLargeCompression(true, input, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    char[] contents = input.toArray();
    String msg = new String(contents);
    String leadingPart = msg.substring(0, 100);
    int count = 10;
    for (int i = 0; i < count; i++) {
        this.sendJmsMessage(msg);
    }
    ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
    subFrame.addHeader("subscription-type", "ANYCAST");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    conn.sendFrame(subFrame);
    for (int i = 0; i < count; i++) {
        ClientStompFrame receiveFrame = conn.receiveFrame(30000);
        Assert.assertNotNull(receiveFrame);
        System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 250));
        Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
        Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
        int index = receiveFrame.getBody().indexOf(leadingPart);
        assertEquals(msg.length(), (receiveFrame.getBody().length() - index));
    }
    // remove suscription
    ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    unsubFrame.addHeader("receipt", "567");
    ClientStompFrame response = conn.sendFrame(unsubFrame);
    assertNotNull(response);
    assertNotNull(response.getCommand().equals("RECEIPT"));
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) LargeMessageTestBase(org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 28 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTestBase method subscribe.

public static ClientStompFrame subscribe(StompClientConnection conn, String subscriptionId, String ack, String durableId, String selector, String destination, boolean receipt) throws IOException, InterruptedException {
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SUBSCRIBE).addHeader(Stomp.Headers.Subscribe.SUBSCRIPTION_TYPE, RoutingType.ANYCAST.toString()).addHeader(Stomp.Headers.Subscribe.DESTINATION, destination);
    if (subscriptionId != null) {
        frame.addHeader(Stomp.Headers.Subscribe.ID, subscriptionId);
    }
    if (ack != null) {
        frame.addHeader(Stomp.Headers.Subscribe.ACK_MODE, ack);
    }
    if (durableId != null) {
        frame.addHeader(Stomp.Headers.Subscribe.DURABLE_SUBSCRIPTION_NAME, durableId);
    }
    if (selector != null) {
        frame.addHeader(Stomp.Headers.Subscribe.SELECTOR, selector);
    }
    String uuid = UUID.randomUUID().toString();
    if (receipt) {
        frame.addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
    }
    frame = conn.sendFrame(frame);
    // Return Error Frame back to the client
    if (frame != null && frame.getCommand().equals("ERROR")) {
        return frame;
    }
    if (receipt) {
        assertEquals(uuid, frame.getHeader(Stomp.Headers.Response.RECEIPT_ID));
    }
    return frame;
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Example 29 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTestBase method ack.

public static void ack(StompClientConnection conn, String subscriptionId, ClientStompFrame messageIdFrame) throws IOException, InterruptedException {
    String messageID = messageIdFrame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.ACK).addHeader(Stomp.Headers.Message.MESSAGE_ID, messageID);
    if (subscriptionId != null) {
        frame.addHeader(Stomp.Headers.Ack.SUBSCRIPTION, subscriptionId);
    }
    ClientStompFrame response = conn.sendFrame(frame);
    if (response != null) {
        throw new IOException("failed to ack " + response);
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) IOException(java.io.IOException)

Example 30 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTestBase method commitTransaction.

public static void commitTransaction(StompClientConnection conn, String txID, boolean receipt) throws IOException, InterruptedException {
    ClientStompFrame beginFrame = conn.createFrame(Stomp.Commands.COMMIT).addHeader(Stomp.Headers.TRANSACTION, txID);
    String uuid = UUID.randomUUID().toString();
    if (receipt) {
        beginFrame.addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
    }
    ClientStompFrame resp = conn.sendFrame(beginFrame);
    if (receipt) {
        assertEquals(uuid, resp.getHeader(Stomp.Headers.Response.RECEIPT_ID));
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Aggregations

ClientStompFrame (org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)195 Test (org.junit.Test)173 MessageConsumer (javax.jms.MessageConsumer)67 TextMessage (javax.jms.TextMessage)62 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 BytesMessage (javax.jms.BytesMessage)43 StompClientConnection (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection)41 Message (javax.jms.Message)37 IOException (java.io.IOException)7 URI (java.net.URI)5 MessageProducer (javax.jms.MessageProducer)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)4 ClosedChannelException (java.nio.channels.ClosedChannelException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 LargeMessageTestBase (org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1