Search in sources :

Example 6 with ClientStompFrame

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

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

the class StompTest method testSubscribeWithAutoAckAndBytesMessage.

@Test
public void testSubscribeWithAutoAckAndBytesMessage() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);
    byte[] payload = new byte[] { 1, 2, 3, 4, 5 };
    sendJmsMessage(payload, queue);
    ClientStompFrame frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Pattern cl = Pattern.compile(Stomp.Headers.CONTENT_LENGTH + ":\\s*(\\d+)", Pattern.CASE_INSENSITIVE);
    Matcher cl_matcher = cl.matcher(frame.toString());
    Assert.assertTrue(cl_matcher.find());
    Assert.assertEquals("5", cl_matcher.group(1));
    Assert.assertFalse(Pattern.compile("type:\\s*null", Pattern.CASE_INSENSITIVE).matcher(frame.toString()).find());
    Assert.assertTrue(frame.getBody().toString().indexOf(new String(payload)) > -1);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 8 with ClientStompFrame

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

the class StompTest method testUnsubscribe.

@Test
public void testUnsubscribe() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);
    // send a message to our queue
    sendJmsMessage("first message");
    // receive message
    ClientStompFrame frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    // remove suscription
    unsubscribe(conn, null, getQueuePrefix() + getQueueName(), true, false);
    // send a message to our queue
    sendJmsMessage("second message");
    frame = conn.receiveFrame(1000);
    log.info("Received frame: " + frame);
    Assert.assertNull("No message should have been received since subscription was removed", frame);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 9 with ClientStompFrame

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

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

the class StompTest method testSendMessageWithContentLength.

@Test
public void testSendMessageWithContentLength() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    conn.connect(defUser, defPass);
    byte[] data = new byte[] { 1, 0, 0, 4 };
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(data);
    baos.flush();
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_LENGTH, Integer.toString(data.length)).setBody(new String(baos.toByteArray()));
    conn.sendFrame(frame);
    BytesMessage message = (BytesMessage) consumer.receive(10000);
    Assert.assertNotNull(message);
    assertEquals(data.length, message.getBodyLength());
    assertEquals(data[0], message.readByte());
    assertEquals(data[1], message.readByte());
    assertEquals(data[2], message.readByte());
    assertEquals(data[3], message.readByte());
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

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