Search in sources :

Example 61 with ClientStompFrame

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

the class StompV12Test method testSendMessageWithLeadingNewLine.

@Test
public void testSendMessageWithLeadingNewLine() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    conn.connect(defUser, defPass);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).setBody("Hello World");
    conn.sendWickedFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
    Assert.assertNull(consumer.receive(1000));
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 62 with ClientStompFrame

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

the class StompV12Test method testSendMessageWithCustomHeadersAndSelector.

@Test
public void testSendMessageWithCustomHeadersAndSelector() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue, "foo = 'abc'");
    conn.connect(defUser, defPass);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader("foo", "abc").addHeader("bar", "123").setBody("Hello World");
    conn.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 63 with ClientStompFrame

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

the class StompV12Test method testSendWithHeartBeatsAndReceiveWithHeartBeats.

@Test
public void testSendWithHeartBeatsAndReceiveWithHeartBeats() throws Exception {
    StompClientConnection newConn = null;
    try {
        ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
        conn.sendFrame(frame);
        conn.startPinger(500);
        for (int i = 0; i < 10; i++) {
            send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World " + i + "!");
            Thread.sleep(500);
        }
        // subscribe
        newConn = StompClientConnectionFactory.createClientConnection(uri);
        frame = newConn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
        newConn.sendFrame(frame);
        newConn.startPinger(500);
        Thread.sleep(500);
        subscribe(newConn, "a-sub");
        int cnt = 0;
        frame = newConn.receiveFrame();
        while (frame != null) {
            cnt++;
            Thread.sleep(500);
            frame = newConn.receiveFrame(5000);
        }
        Assert.assertEquals(10, cnt);
        // unsub
        unsubscribe(newConn, "a-sub");
    } finally {
        if (newConn != null)
            newConn.disconnect();
        conn.disconnect();
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Example 64 with ClientStompFrame

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

the class StompV12Test method testNackWithWrongMessageId.

@Test
public void testNackWithWrongMessageId() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client");
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertNotNull(frame);
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Subscribe.ACK_MODE));
    nack(conn, "someother");
    ClientStompFrame error = conn.receiveFrame();
    System.out.println("Receiver error: " + error);
    waitDisconnect(conn);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", conn.isConnected());
    // message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(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 65 with ClientStompFrame

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

the class StompV12Test method testAckNoIDHeader.

@Test
public void testAckNoIDHeader() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client-individual");
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    String messageID = frame.getHeader(Stomp.Headers.Subscribe.ACK_MODE);
    Assert.assertNotNull(messageID);
    ClientStompFrame ackFrame = conn.createFrame(Stomp.Commands.ACK);
    conn.sendFrame(ackFrame);
    frame = conn.receiveFrame();
    Assert.assertEquals(Stomp.Responses.ERROR, frame.getCommand());
    waitDisconnect(conn);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", conn.isConnected());
    // message still there.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(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)

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