Search in sources :

Example 81 with ClientStompFrame

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

the class StompV11Test 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 };
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).setBody(new String(data, StandardCharsets.UTF_8)).addHeader(Stomp.Headers.CONTENT_LENGTH, String.valueOf(data.length));
    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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 82 with ClientStompFrame

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

the class StompV11Test method testSubscribeWithAutoAck.

@Test
public void testSubscribeWithAutoAck() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Message.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    conn.disconnect();
    // message should not be received as it was auto-acked
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Test(org.junit.Test)

Example 83 with ClientStompFrame

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

the class StompV11Test method testHeaderContentLength.

@Test
public void testHeaderContentLength() throws Exception {
    conn.connect(defUser, defPass);
    String body = "Hello World 1!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).setBody(body + "extra");
    conn.sendFrame(frame);
    // subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
    newConn.connect(defUser, defPass);
    subscribe(newConn, "a-sub");
    frame = newConn.receiveFrame();
    IntegrationTestLogger.LOGGER.info("received " + frame);
    assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    assertEquals(cLen, frame.getHeader(Stomp.Headers.CONTENT_LENGTH));
    // unsub
    unsubscribe(newConn, "a-sub");
    newConn.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 84 with ClientStompFrame

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

the class StompV11Test method testAckModeAuto.

@Test
public void testAckModeAuto() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
    int num = 50;
    // send a bunch of messages
    for (int i = 0; i < num; i++) {
        this.sendJmsMessage("auto-ack" + i);
    }
    ClientStompFrame frame = null;
    for (int i = 0; i < num; i++) {
        frame = conn.receiveFrame();
        assertNotNull(frame);
    }
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // no messages can be received.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Test(org.junit.Test)

Example 85 with ClientStompFrame

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

the class StompV11Test method testSubscribeWithClientAck.

@Test
public void testSubscribeWithClientAck() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    assertEquals(getName().length(), Integer.parseInt(frame.getHeader(Stomp.Headers.CONTENT_LENGTH)));
    ack(conn, "sub1", frame);
    conn.disconnect();
    // message should not be received since message was acknowledged by the client
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) 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