Search in sources :

Example 1 with ClientStompFrame

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

the class AMQPToStompTest method testSendAmqpReceiveStomp.

@Test
public void testSendAmqpReceiveStomp() throws Exception {
    AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
    AmqpConnection amqpconnection = client.connect();
    try {
        AmqpSession session = amqpconnection.createSession();
        AmqpSender sender = session.createSender(queueName);
        AmqpMessage message = new AmqpMessage();
        message.setText("mine");
        sender.send(message);
    } finally {
        amqpconnection.close();
    }
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(new URI("tcp://127.0.0.1:61616"));
    conn.connect(null, null);
    try {
        StompTestBase.subscribeQueue(conn, null, queueName);
        ClientStompFrame frame = conn.receiveFrame();
        assertNotNull(frame);
        assertNotNull(frame.getBody());
        assertTrue(frame.getBody().contains("mine"));
    } finally {
        conn.closeTransport();
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 2 with ClientStompFrame

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

the class StompTest method assertSubscribeWithClientAckThenConsumeWithAutoAck.

protected void assertSubscribeWithClientAckThenConsumeWithAutoAck(boolean sendDisconnect) throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    log.info("Reconnecting!");
    if (sendDisconnect) {
        conn.disconnect();
        conn.destroy();
        conn = StompClientConnectionFactory.createClientConnection(uri);
    } else {
        conn.destroy();
        conn = StompClientConnectionFactory.createClientConnection(uri);
    }
    // message should be received since message was not acknowledged
    conn.connect(defUser, defPass);
    subscribe(conn, null);
    frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    conn.disconnect();
    conn.destroy();
    conn = StompClientConnectionFactory.createClientConnection(uri);
    // now let's make sure we don't see the message again
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO, null, true);
    sendJmsMessage("shouldBeNextMessage");
    frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals("shouldBeNextMessage", frame.getBody());
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Example 3 with ClientStompFrame

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

the class StompTest method testSubscribeWithClientAck.

@Test
public void testSubscribeWithClientAck() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Message.MESSAGE_ID));
    ack(conn, null, 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) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Test(org.junit.Test)

Example 4 with ClientStompFrame

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

the class StompTest method testSubscribeToTopicWithNoLocal.

@Test
public void testSubscribeToTopicWithNoLocal() throws Exception {
    conn.connect(defUser, defPass);
    subscribeTopic(conn, null, null, null, true, true);
    // send a message on the same connection => it should not be received is noLocal = true on subscribe
    send(conn, getTopicPrefix() + getTopicName(), null, "Hello World");
    ClientStompFrame frame = conn.receiveFrame(2000);
    log.info("Received frame: " + frame);
    Assert.assertNull("No message should have been received since subscription was removed", frame);
    // send message on another JMS connection => it should be received
    sendJmsMessage(getName(), topic);
    frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals(getTopicPrefix() + getTopicName(), frame.getHeader(Stomp.Headers.Send.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 5 with ClientStompFrame

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

the class StompTest method testUnsubscribeWithID.

@Test
public void testUnsubscribeWithID() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "mysubid", Stomp.Headers.Subscribe.AckModeValues.AUTO);
    // send a message to our queue
    sendJmsMessage("first message");
    // receive message from socket
    ClientStompFrame frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    // remove suscription
    unsubscribe(conn, "mysubid", null, 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)

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