Search in sources :

Example 11 with ClientStompFrame

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

the class StompTest method testMultiProtocolConsumers.

// HORNETQ-1007
@Test
public void testMultiProtocolConsumers() throws Exception {
    final int TIME_OUT = 2000;
    int count = 1000;
    // Create 2 core consumers
    MessageConsumer consumer1 = session.createConsumer(topic);
    MessageConsumer consumer2 = session.createConsumer(topic);
    // connect and subscribe STOMP consumer
    conn.connect(defUser, defPass);
    subscribeTopic(conn, null, null, null, true);
    MessageProducer producer = session.createProducer(topic);
    TextMessage message = session.createTextMessage(getName());
    for (int i = 1; i <= count; i++) {
        producer.send(message);
        Assert.assertNotNull(consumer1.receive(TIME_OUT));
        Assert.assertNotNull(consumer2.receive(TIME_OUT));
        ClientStompFrame frame = conn.receiveFrame(TIME_OUT);
        Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
        Assert.assertEquals(getTopicPrefix() + getTopicName(), frame.getHeader(Stomp.Headers.Send.DESTINATION));
        Assert.assertEquals(getName(), frame.getBody());
    }
    consumer1.close();
    consumer2.close();
    unsubscribe(conn, null, getTopicPrefix() + getTopicName(), true, false);
    sendJmsMessage(getName(), topic);
    ClientStompFrame frame = conn.receiveFrame(TIME_OUT);
    log.info("Received frame: " + frame);
    Assert.assertNull("No message should have been received since subscription was removed", frame);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 12 with ClientStompFrame

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

the class StompTest method testBeginSameTransactionTwice.

@Test
public void testBeginSameTransactionTwice() throws Exception {
    conn.connect(defUser, defPass);
    beginTransaction(conn, "tx1");
    beginTransaction(conn, "tx1");
    ClientStompFrame frame = conn.receiveFrame(1000);
    Assert.assertEquals(Stomp.Responses.ERROR, frame.getCommand());
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 13 with ClientStompFrame

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

the class StompTest method testSendMessageWithDelay.

@Test
public void testSendMessageWithDelay() 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("foo", "abc").addHeader("bar", "123").addHeader("correlation-id", "c123").addHeader("persistent", "true").addHeader("type", "t345").addHeader("JMSXGroupID", "abc").addHeader("priority", "3").addHeader("AMQ_SCHEDULED_DELAY", "2000").setBody("Hello World");
    conn.sendFrame(frame);
    assertNull("Should not receive message yet", consumer.receive(1000));
    TextMessage message = (TextMessage) consumer.receive(4000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(javax.jms.DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("JMSXGroupID", "abc", 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 14 with ClientStompFrame

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

the class StompTest method sendMQTTReceiveSTOMP.

@Test
public void sendMQTTReceiveSTOMP() throws Exception {
    String payload = "This is a test message";
    // Set up STOMP subscription
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);
    // Send MQTT Message
    MQTTClientProvider clientProvider = new FuseMQTTClientProvider();
    clientProvider.connect("tcp://" + hostname + ":" + port);
    clientProvider.publish(getQueuePrefix() + getQueueName(), payload.getBytes(), 0);
    clientProvider.disconnect();
    // Receive STOMP Message
    ClientStompFrame frame = conn.receiveFrame();
    assertTrue(frame.getBody().contains(payload));
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) FuseMQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.FuseMQTTClientProvider) MQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FuseMQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.FuseMQTTClientProvider) Test(org.junit.Test)

Example 15 with ClientStompFrame

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

the class StompTest method testSubscribeToTopic.

@Test
public void testSubscribeToTopic() throws Exception {
    final int baselineQueueCount = server.getActiveMQServer().getActiveMQServerControl().getQueueNames().length;
    conn.connect(defUser, defPass);
    subscribeTopic(conn, null, null, null, true);
    assertTrue("Subscription queue should be created here", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisfied() throws Exception {
            int length = server.getActiveMQServer().getActiveMQServerControl().getQueueNames().length;
            if (length - baselineQueueCount == 1) {
                return true;
            } else {
                log.info("Queue count: " + (length - baselineQueueCount));
                return false;
            }
        }
    }, TimeUnit.SECONDS.toMillis(10), TimeUnit.MILLISECONDS.toMillis(100)));
    sendJmsMessage(getName(), topic);
    ClientStompFrame frame = conn.receiveFrame(1000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals(getTopicPrefix() + getTopicName(), frame.getHeader(Stomp.Headers.Send.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    unsubscribe(conn, null, getTopicPrefix() + getTopicName(), true, false);
    sendJmsMessage(getName(), topic);
    frame = conn.receiveFrame(1000);
    log.info("Received frame: " + frame);
    Assert.assertNull("No message should have been received since subscription was removed", frame);
    assertEquals("Subscription queue should be deleted", 0, server.getActiveMQServer().getActiveMQServerControl().getQueueNames().length - baselineQueueCount);
    conn.disconnect();
}
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