Search in sources :

Example 1 with StompClientConnection

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

the class AMQPToStompTest method testSendAmqpReceiveStomp.

@Test
public void testSendAmqpReceiveStomp() throws Exception {
    AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
    AmqpConnection amqpconnection = client.connect();
    try {
        AmqpSession session = amqpconnection.createSession();
        AmqpSender sender = session.createSender(queueName);
        AmqpMessage message = new AmqpMessage();
        message.setText("mine");
        sender.send(message);
    } finally {
        amqpconnection.close();
    }
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(new URI("tcp://127.0.0.1:61616"));
    conn.connect(null, null);
    try {
        StompTestBase.subscribeQueue(conn, null, queueName);
        ClientStompFrame frame = conn.receiveFrame();
        assertNotNull(frame);
        assertNotNull(frame.getBody());
        assertTrue(frame.getBody().contains("mine"));
    } finally {
        conn.closeTransport();
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 2 with StompClientConnection

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

the class StompTest method testPrefixedSendAndRecieve.

public void testPrefixedSendAndRecieve(final String prefix, RoutingType routingType) throws Exception {
    int port = 61614;
    URI uri = createStompClientUri(scheme, hostname, port);
    final String ADDRESS = UUID.randomUUID().toString();
    final String PREFIXED_ADDRESS = prefix + ADDRESS;
    String urlParam = routingType.toString().toLowerCase() + "Prefix";
    server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://" + hostname + ":" + port + "?protocols=" + StompProtocolManagerFactory.STOMP_PROTOCOL_NAME + "&" + urlParam + "=" + prefix).start();
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass);
    String uuid = UUID.randomUUID().toString();
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SUBSCRIBE).addHeader(Stomp.Headers.Subscribe.DESTINATION, PREFIXED_ADDRESS).addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
    frame = conn.sendFrame(frame);
    assertEquals(uuid, frame.getHeader(Stomp.Headers.Response.RECEIPT_ID));
    send(conn, ADDRESS, null, "Hello World", true);
    frame = conn.receiveFrame(10000);
    Assert.assertNotNull("Should have received a message", frame);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals(ADDRESS, frame.getHeader(Stomp.Headers.Send.DESTINATION));
    Assert.assertEquals("Hello World", frame.getBody());
    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) URI(java.net.URI)

Example 3 with StompClientConnection

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

the class StompTest method testConnectionTTL.

@Test
public void testConnectionTTL() throws Exception {
    int port = 61614;
    URI uri = createStompClientUri(scheme, hostname, port);
    server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?connectionTtl=1000").start();
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect("brianm", "wombats");
    Thread.sleep(5000);
    ClientStompFrame frame = conn.receiveFrame();
    assertEquals(Stomp.Responses.ERROR, frame.getCommand());
    assertFalse(conn.isConnected());
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) URI(java.net.URI) Test(org.junit.Test)

Example 4 with StompClientConnection

use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection 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 5 with StompClientConnection

use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection 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)

Aggregations

StompClientConnection (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection)44 Test (org.junit.Test)42 ClientStompFrame (org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)41 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 URI (java.net.URI)7 IOException (java.io.IOException)2 MessageConsumer (javax.jms.MessageConsumer)2 TextMessage (javax.jms.TextMessage)2 LargeMessageTestBase (org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase)2 StompClientConnectionV11 (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11)2 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 Message (javax.jms.Message)1 QueueBrowser (javax.jms.QueueBrowser)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)1 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1