Added dependency to Paho 1.2.0
This commit is contained in:
+2
-2
@@ -30,9 +30,9 @@ dependencies {
|
|||||||
testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.5'
|
testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.5'
|
||||||
|
|
||||||
testCompile group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version:'1.12'
|
testCompile group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version:'1.12'
|
||||||
testCompile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version:'1.0.2'
|
testCompile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version:'1.2.0'
|
||||||
testCompile group: 'org.eclipse.jetty.websocket', name: 'websocket-client', version:'9.2.0.M1'
|
testCompile group: 'org.eclipse.jetty.websocket', name: 'websocket-client', version:'9.2.0.M1'
|
||||||
|
|
||||||
testCompile group: 'com.h2database', name: 'h2', version:'1.4.191'
|
testCompile group: 'com.h2database', name: 'h2', version:'1.4.191'
|
||||||
testRuntime group: 'io.netty', name: 'netty-tcnative', version: '2.0.10.Final', classifier: 'linux-x86_64'
|
testRuntime group: 'io.netty', name: 'netty-tcnative', version: '2.0.10.Final', classifier: 'linux-x86_64'
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,6 +4,6 @@ dependencies {
|
|||||||
compile project(':moquette-broker')
|
compile project(':moquette-broker')
|
||||||
compile group: 'io.netty', name: 'netty-codec-mqtt', version:"${nettyVersion}"
|
compile group: 'io.netty', name: 'netty-codec-mqtt', version:"${nettyVersion}"
|
||||||
compile group: 'org.hdrhistogram', name: 'HdrHistogram', version:'2.1.2'
|
compile group: 'org.hdrhistogram', name: 'HdrHistogram', version:'2.1.2'
|
||||||
compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version:'1.1.0'
|
compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version:'1.2.0'
|
||||||
compile group: 'org.eclipse.jetty.toolchain', name: 'jetty-perf-helper', version:'1.0.5'
|
compile group: 'org.eclipse.jetty.toolchain', name: 'jetty-perf-helper', version:'1.0.5'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,8 @@
|
|||||||
@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/')
|
@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/')
|
||||||
@Grab(group='org.eclipse.paho', module='mqtt-client', version='0.4.0')
|
@Grab(group='org.eclipse.paho', module='org.eclipse.paho.client.mqttv3', version='1.2.0')
|
||||||
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttClient
|
import org.eclipse.paho.client.mqttv3.MqttClient
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
|
||||||
import org.eclipse.paho.client.mqttv3.MqttException
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttCallback
|
|
||||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
|
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions
|
|
||||||
import java.util.concurrent.CountDownLatch
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
|
|
||||||
class SubscriberCallback implements MqttCallback {
|
|
||||||
|
|
||||||
int m_numReceived = 0
|
|
||||||
long m_startTime
|
|
||||||
boolean firstMessageReceived = false
|
|
||||||
|
|
||||||
private CountDownLatch m_latch = new CountDownLatch(1)
|
|
||||||
|
|
||||||
void waitFinish() {
|
|
||||||
m_latch.await()
|
|
||||||
}
|
|
||||||
|
|
||||||
public void connectionLost(Throwable cause) {
|
|
||||||
m_latch.countDown()
|
|
||||||
}
|
|
||||||
|
|
||||||
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
|
||||||
//println "Received message ${new String(message.payload)} on topic [${topic}]"
|
|
||||||
if (!firstMessageReceived) {
|
|
||||||
m_startTime = System.currentTimeMillis()
|
|
||||||
firstMessageReceived = true
|
|
||||||
}
|
|
||||||
if (topic == "/exit") {
|
|
||||||
long stopTime = System.currentTimeMillis()
|
|
||||||
long spentTime = stopTime - m_startTime
|
|
||||||
println "/exit received"
|
|
||||||
println "subscriber disconnected, received ${m_numReceived} messages in ${spentTime} ms"
|
|
||||||
m_latch.countDown()
|
|
||||||
} else {
|
|
||||||
//println "-received ${message} on ${topic} with QoS ${message.qos}"
|
|
||||||
m_numReceived++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
println "Usage subscriber <host> <QoS>"
|
println "Usage subscriber <host> <QoS>"
|
||||||
@@ -58,24 +11,14 @@ if (args.size() < 2) {
|
|||||||
|
|
||||||
String host = args[0]
|
String host = args[0]
|
||||||
int qos = args[1] as int
|
int qos = args[1] as int
|
||||||
String tmpDir = System.getProperty("java.io.tmpdir")
|
MemoryPersistence persistence = new MemoryPersistence()
|
||||||
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir)
|
|
||||||
|
|
||||||
int rnd = (Math.random() * 100) as int
|
MqttClient client = new MqttClient("tcp://${host}:1883", "SubscriberClient", persistence)
|
||||||
MqttClient client = new MqttClient("tcp://${host}:1883", "SubscriberClient${rnd}", dataStore)
|
|
||||||
def callback = new SubscriberCallback()
|
|
||||||
client.callback = callback
|
|
||||||
//Only for Apollo ---
|
|
||||||
//MqttConnectOptions connOptions = new MqttConnectOptions()
|
|
||||||
//connOptions.userName ='admin'
|
|
||||||
//connOptions.password = 'password' as char[]
|
|
||||||
//client.connect(connOptions)
|
|
||||||
//Only for Apollo ---
|
|
||||||
client.connect()
|
client.connect()
|
||||||
client.subscribe("topic", 0)
|
client.subscribe("topic", 0)
|
||||||
println "subscribed to topic"
|
println "subscribed to topic"
|
||||||
client.subscribe("/exit", 0)
|
client.unsubscribe("topic")
|
||||||
println "subscribed to /exit"
|
println "unsubscribed from topic"
|
||||||
|
|
||||||
callback.waitFinish()
|
client.disconnect()
|
||||||
client.diconnect()
|
client.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user