Fixed issue #15, missed notification of publish due to bad re-activation on a nested topic tree.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
@Grab(group='org.fusesource.mqtt-client', module='mqtt-client', version='1.5')
|
||||
|
||||
import java.net.URISyntaxException
|
||||
|
||||
import org.fusesource.mqtt.client.BlockingConnection
|
||||
import org.fusesource.mqtt.client.MQTT
|
||||
import org.fusesource.mqtt.client.Message
|
||||
import org.fusesource.mqtt.client.QoS
|
||||
import org.fusesource.mqtt.client.Topic
|
||||
|
||||
class Reciever {
|
||||
MQTT mqtt = new MQTT()
|
||||
BlockingConnection connection
|
||||
|
||||
public void connectAndSubscribe(boolean cleanSession) {
|
||||
mqtt.setCleanSession(cleanSession)
|
||||
mqtt.setHost("localhost", 1883)
|
||||
|
||||
mqtt.setClientId("reciever")
|
||||
connection = mqtt.blockingConnection()
|
||||
connection.connect()
|
||||
Topic[] topics = [new Topic("/topic", QoS.AT_LEAST_ONCE)]
|
||||
byte[] qoses = connection.subscribe(topics)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reciever r = new Reciever()
|
||||
r.connectAndSubscribe(false)
|
||||
Message message
|
||||
3.times { i ->
|
||||
message = r.connection.receive()
|
||||
println "Topic: ${message.topic}, payload: ${new String(message.payload)}"
|
||||
message.ack()
|
||||
}
|
||||
r.connection.kill()
|
||||
//r.connection.disconnect()
|
||||
|
||||
Thread.sleep(3000)
|
||||
|
||||
r.connectAndSubscribe(false)
|
||||
3.times { i ->
|
||||
message = r.connection.receive()
|
||||
println "Topic: ${message.topic}, payload: ${new String(message.payload)}"
|
||||
message.ack()
|
||||
}
|
||||
r.connection.disconnect()
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/')
|
||||
@Grab(group='org.fusesource.mqtt-client', module='mqtt-client', version='1.5')
|
||||
|
||||
import java.net.URISyntaxException
|
||||
|
||||
import org.fusesource.mqtt.client.BlockingConnection
|
||||
import org.fusesource.mqtt.client.MQTT
|
||||
import org.fusesource.mqtt.client.QoS
|
||||
|
||||
|
||||
MQTT mqtt = new MQTT()
|
||||
//mqtt.setHost("test.mosquitto.org", 1883);
|
||||
mqtt.setHost("localhost", 1883)
|
||||
|
||||
BlockingConnection connection = mqtt.blockingConnection()
|
||||
connection.connect()
|
||||
|
||||
//for (int i = 0; i < 1000; i++) {
|
||||
(1..1000).each{ i ->
|
||||
// LOG.info("Publishing");
|
||||
String payload = "Hello world MQTT!!${i}"
|
||||
connection.publish("/topic", payload.getBytes(), QoS.AT_LEAST_ONCE, false)
|
||||
println payload
|
||||
Thread.sleep 1000
|
||||
}
|
||||
|
||||
connection.disconnect()
|
||||
Reference in New Issue
Block a user