Search in sources :

Example 1 with MQTTClientProvider

use of org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider 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 2 with MQTTClientProvider

use of org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider in project activemq-artemis by apache.

the class MqttPluginTest method testSendAndReceiveMQTT.

@Test(timeout = 60 * 1000)
public void testSendAndReceiveMQTT() throws Exception {
    final MQTTClientProvider subscriptionProvider = getMQTTClientProvider();
    initializeConnection(subscriptionProvider);
    subscriptionProvider.subscribe("foo/bah", AT_MOST_ONCE);
    final CountDownLatch latch = new CountDownLatch(NUM_MESSAGES);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < NUM_MESSAGES; i++) {
                try {
                    byte[] payload = subscriptionProvider.receive(10000);
                    assertNotNull("Should get a message", payload);
                    latch.countDown();
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
            }
        }
    });
    thread.start();
    final MQTTClientProvider publishProvider = getMQTTClientProvider();
    initializeConnection(publishProvider);
    for (int i = 0; i < NUM_MESSAGES; i++) {
        String payload = "Message " + i;
        publishProvider.publish("foo/bah", payload.getBytes(), AT_LEAST_ONCE);
    }
    latch.await(10, TimeUnit.SECONDS);
    assertEquals(0, latch.getCount());
    subscriptionProvider.disconnect();
    publishProvider.disconnect();
    verifier.validatePluginMethodsEquals(0, MESSAGE_EXPIRED, BEFORE_DEPLOY_BRIDGE, AFTER_DEPLOY_BRIDGE);
    verifier.validatePluginMethodsAtLeast(1, AFTER_CREATE_CONNECTION, AFTER_DESTROY_CONNECTION, BEFORE_CREATE_SESSION, AFTER_CREATE_SESSION, BEFORE_CLOSE_SESSION, AFTER_CLOSE_SESSION, BEFORE_CREATE_CONSUMER, AFTER_CREATE_CONSUMER, BEFORE_CLOSE_CONSUMER, AFTER_CLOSE_CONSUMER, BEFORE_CREATE_QUEUE, AFTER_CREATE_QUEUE, MESSAGE_ACKED, BEFORE_SEND, AFTER_SEND, BEFORE_MESSAGE_ROUTE, AFTER_MESSAGE_ROUTE, BEFORE_DELIVER, AFTER_DELIVER, BEFORE_ADD_ADDRESS, AFTER_ADD_ADDRESS, BEFORE_ADD_BINDING, AFTER_ADD_BINDING, BEFORE_REMOVE_BINDING, AFTER_REMOVE_BINDING);
}
Also used : MQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with MQTTClientProvider

use of org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider in project activemq-artemis by apache.

the class MqttPluginTest method testMQTTAutoCreate.

@Test(timeout = 60 * 1000)
public void testMQTTAutoCreate() throws Exception {
    final MQTTClientProvider subscriptionProvider = getMQTTClientProvider();
    initializeConnection(subscriptionProvider);
    subscriptionProvider.subscribe("foo/bah", AT_MOST_ONCE);
    subscriptionProvider.disconnect();
    verifier.validatePluginMethodsAtLeast(1, BEFORE_ADD_ADDRESS, AFTER_ADD_ADDRESS, BEFORE_REMOVE_ADDRESS, AFTER_REMOVE_ADDRESS);
}
Also used : MQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider) Test(org.junit.Test)

Example 4 with MQTTClientProvider

use of org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider in project activemq-artemis by apache.

the class StompTest method sendSTOMPReceiveMQTT.

@Test
public void sendSTOMPReceiveMQTT() throws Exception {
    // Set up MQTT Subscription
    MQTTClientProvider clientProvider = new FuseMQTTClientProvider();
    clientProvider.connect("tcp://" + hostname + ":" + port);
    clientProvider.subscribe(getTopicPrefix() + getTopicName(), 0);
    String stompPayload = "This is a test message";
    // Set up STOMP connection and send STOMP Message
    conn.connect(defUser, defPass);
    send(conn, getTopicPrefix() + getTopicName(), null, stompPayload);
    // Receive MQTT Message
    byte[] mqttPayload = clientProvider.receive(10000);
    clientProvider.disconnect();
    assertEquals(stompPayload, new String(mqttPayload, "UTF-8"));
    clientProvider.disconnect();
}
Also used : FuseMQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.FuseMQTTClientProvider) MQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider) FuseMQTTClientProvider(org.apache.activemq.artemis.tests.integration.mqtt.imported.FuseMQTTClientProvider) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Aggregations

MQTTClientProvider (org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTClientProvider)4 Test (org.junit.Test)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 FuseMQTTClientProvider (org.apache.activemq.artemis.tests.integration.mqtt.imported.FuseMQTTClientProvider)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ClientStompFrame (org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)1