Package org.fusesource.mqtt.client

Examples of org.fusesource.mqtt.client.Topic


        try {
            for (SubscriptionInfo sub : subs) {
                String name = sub.getSubcriptionName();
                String[] split = name.split(":", 2);
                QoS qoS = QoS.valueOf(split[0]);
                onSubscribe(new Topic(split[1], qoS));
                // mark this durable subscription as restored by Broker
                restoredSubs.add(split[1]);
            }
        } catch (IOException e) {
            LOG.warn("Could not restore the MQTT durable subs.", e);
View Full Code Here


        // create a subscription with Clean == 0 (durable sub for QoS==1 && QoS==2)
        // on the remote broker. this sub should still be there after we disconnect
        MQTT remoteMqtt = createMQTTTcpConnection("foo", false, remoteBrokerMQTTPort);
        BlockingConnection remoteConn = remoteMqtt.blockingConnection();
        remoteConn.connect();
        remoteConn.subscribe(new Topic[]{new Topic("foo/bar", QoS.AT_LEAST_ONCE)});

        assertTrue("No destination detected!", consumerNetworked.await(1, TimeUnit.SECONDS));
        assertQueueExistsOn(remoteBroker, "Consumer.foo_AT_LEAST_ONCE.VirtualTopic.foo.bar");
        assertQueueExistsOn(broker, "Consumer.foo_AT_LEAST_ONCE.VirtualTopic.foo.bar");
        remoteConn.disconnect();

        // now we reconnect the same sub on the local broker, again with clean==0
        MQTT localMqtt = createMQTTTcpConnection("foo", false, localBrokerMQTTPort);
        BlockingConnection localConn = localMqtt.blockingConnection();
        localConn.connect();
        localConn.subscribe(new Topic[]{new Topic("foo/bar", QoS.AT_LEAST_ONCE)});

        // now let's connect back up to remote broker and send a message
        remoteConn = remoteMqtt.blockingConnection();
        remoteConn.connect();
        remoteConn.publish("foo/bar", "Hello, World!".getBytes(), QoS.AT_LEAST_ONCE, false);

        // now we should see that message on the local broker because the subscription
        // should have been properly networked... we'll give a sec of grace for the
        // networking and forwarding to have happened properly
        org.fusesource.mqtt.client.Message msg = localConn.receive(100, TimeUnit.SECONDS);
        assertNotNull(msg);
        msg.ack();
        String response = new String(msg.getPayload());
        assertEquals("Hello, World!", response);
        assertEquals("foo/bar", msg.getTopic());

        // Now... we SHOULD NOT see a message on the remote broker because we already
        // consumed it on the local broker... having the same message on the remote broker
        // would effectively give us duplicates in a distributed topic scenario:
        remoteConn.subscribe(new Topic[]{new Topic("foo/bar", QoS.AT_LEAST_ONCE)});
        msg = remoteConn.receive(500, TimeUnit.MILLISECONDS);
        assertNull("We have duplicate messages across the cluster for a distributed topic", msg);
    }
View Full Code Here

        try {
            for (SubscriptionInfo sub : subs) {
                String name = sub.getSubcriptionName();
                String[] split = name.split(":", 2);
                QoS qoS = QoS.valueOf(split[0]);
                onSubscribe(new Topic(split[1], qoS));
                // mark this durable subscription as restored by Broker
                restoredSubs.add(split[1]);
            }
        } catch (IOException e) {
            LOG.warn("Could not restore the MQTT durable subs.", e);
View Full Code Here

    }

    @Before
    public void before() {
        MQTT mqtt = new MQTT();
        Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
        BlockingConnection connection = mqtt.blockingConnection();
        try {
            connection.connect();
            connection.subscribe(new Topic[]{outputTopic});
            while(connection.receive(1000, TimeUnit.MILLISECONDS) != null);
View Full Code Here

    @Ignore("Disable for now due to https://issues.jboss.org/browse/SWITCHYARD-2221")
    @Test
    public void testReferenceBinding() throws Exception {
        MQTT mqtt = new MQTT();
        Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
        BlockingConnection connection = mqtt.blockingConnection();
        try {
            connection.connect();
            connection.subscribe(new Topic[]{outputTopic});
View Full Code Here

        reader.close();

        BlockingConnection publishConnection = null;
        BlockingConnection subscribeConnection = null;
        try {
            Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
            MQTT mqtt = new MQTT();
            mqtt.setUserName(USER_NAME);
            mqtt.setPassword(PASSWORD);
            subscribeConnection = mqtt.blockingConnection();
            subscribeConnection.connect();
View Full Code Here

TOP

Related Classes of org.fusesource.mqtt.client.Topic

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.