Search in sources :

Example 86 with ClientStompFrame

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

the class StompV11Test 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("foo", "abc").addHeader("bar", "123").addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).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 87 with ClientStompFrame

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

the class StompV11Test method testJMSXGroupIdCanBeSet.

@Test
public void testJMSXGroupIdCanBeSet() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    conn.connect(defUser, defPass);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader("JMSXGroupID", "TEST").setBody("Hello World");
    conn.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // differ from StompConnect
    Assert.assertEquals("TEST", message.getStringProperty("JMSXGroupID"));
}
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 88 with ClientStompFrame

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

the class StompV11Test method testClientAckNotPartOfTransaction.

@Test
public void testClientAckNotPartOfTransaction() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, getName(), Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.MESSAGE));
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Message.DESTINATION));
    Assert.assertTrue(frame.getBody().equals(getName()));
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Message.MESSAGE_ID));
    String messageID = frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    beginTransaction(conn, "tx1");
    ack(conn, getName(), messageID, "tx1");
    abortTransaction(conn, "tx1");
    frame = conn.receiveFrame(500);
    assertNull(frame);
    unsubscribe(conn, getName());
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 89 with ClientStompFrame

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

the class StompV11Test 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.Connect.ACCEPT_VERSION, "1.0,1.1");
        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.Connect.ACCEPT_VERSION, "1.0,1.1");
        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);
        }
        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 90 with ClientStompFrame

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

the class StompV11Test method testHeartBeatToConnectionTTLModifier.

@Test
public void testHeartBeatToConnectionTTLModifier() throws Exception {
    ClientStompFrame frame;
    ClientStompFrame reply;
    StompClientConnection connection;
    int port = 61614;
    server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?heartBeatToConnectionTtlModifier=1").start();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    frame = connection.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, "5000,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
    reply = connection.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    assertEquals("0,5000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    Thread.sleep(6000);
    try {
        assertFalse(connection.isConnected());
    } finally {
        connection.closeTransport();
    }
    server.getActiveMQServer().getRemotingService().destroyAcceptor("test");
    server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?heartBeatToConnectionTtlModifier=1.5").start();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    frame = connection.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, "5000,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
    reply = connection.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    assertEquals("0,5000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    Thread.sleep(6000);
    connection.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)

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