Search in sources :

Example 36 with ClientStompFrame

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

the class StompV12Test method ack.

// STOMP 1.2-specific ACK and NACK methods
private void ack(StompClientConnection conn, String mid) throws IOException, InterruptedException {
    ClientStompFrame ackFrame = conn.createFrame(Stomp.Commands.ACK);
    ackFrame.addHeader(Stomp.Headers.Subscribe.ID, mid);
    conn.sendFrame(ackFrame);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Example 37 with ClientStompFrame

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

the class StompV12Test method testSubscribeToTopic.

@Test
public void testSubscribeToTopic() throws Exception {
    conn.connect(defUser, defPass);
    subscribeTopic(conn, "sub1", null, null, true);
    sendJmsMessage(getName(), topic);
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.MESSAGE));
    Assert.assertTrue(frame.getHeader(Stomp.Headers.Subscribe.DESTINATION).equals(getTopicPrefix() + getTopicName()));
    Assert.assertTrue(frame.getBody().equals(getName()));
    unsubscribe(conn, "sub1", true);
    sendJmsMessage(getName(), topic);
    frame = conn.receiveFrame(1000);
    Assert.assertNull(frame);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 38 with ClientStompFrame

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

the class StompV12Test method testNack.

@Test
public void testNack() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client");
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    String messageID = frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    nack(conn, messageID);
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // Nack makes the message be dropped.
    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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 39 with ClientStompFrame

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

the class StompV12Test method testDurableSubscriberWithReconnection.

@Test
public void testDurableSubscriberWithReconnection() throws Exception {
    conn.connect(defUser, defPass, CLIENT_ID);
    subscribeTopic(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, getName());
    ClientStompFrame frame = conn.createFrame("DISCONNECT");
    frame.addHeader(Stomp.Headers.RECEIPT_REQUESTED, "1");
    ClientStompFrame result = conn.sendFrame(frame);
    if (result == null || (!Stomp.Responses.RECEIPT.equals(result.getCommand())) || (!"1".equals(result.getHeader("receipt-id")))) {
        Assert.fail("Disconnect failed! " + result);
    }
    // send the message when the durable subscriber is disconnected
    sendJmsMessage(getName(), topic);
    conn.destroy();
    conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass, CLIENT_ID);
    subscribeTopic(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, getName());
    // we must have received the message
    frame = conn.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.MESSAGE));
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Subscribe.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    unsubscribe(conn, "sub1");
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 40 with ClientStompFrame

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

the class StompV12Test method testSubscribeWithMessageSentWithProperties.

@Test
public void testSubscribeWithMessageSentWithProperties() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
    MessageProducer producer = session.createProducer(queue);
    BytesMessage message = session.createBytesMessage();
    message.setStringProperty("S", "value");
    message.setBooleanProperty("n", false);
    message.setByteProperty("byte", (byte) 9);
    message.setDoubleProperty("d", 2.0);
    message.setFloatProperty("f", (float) 6.0);
    message.setIntProperty("i", 10);
    message.setLongProperty("l", 121);
    message.setShortProperty("s", (short) 12);
    message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
    producer.send(message);
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertNotNull(frame);
    Assert.assertTrue(frame.getHeader("S") != null);
    Assert.assertTrue(frame.getHeader("n") != null);
    Assert.assertTrue(frame.getHeader("byte") != null);
    Assert.assertTrue(frame.getHeader("d") != null);
    Assert.assertTrue(frame.getHeader("f") != null);
    Assert.assertTrue(frame.getHeader("i") != null);
    Assert.assertTrue(frame.getHeader("l") != null);
    Assert.assertTrue(frame.getHeader("s") != null);
    Assert.assertEquals("Hello World", frame.getBody());
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) 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