CountDownLatch consumerNetworked = listenForConsumersOn(broker);
// 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());