This commit is contained in:
parent
0575771daa
commit
5a0e8b842c
@ -6,7 +6,7 @@ class MqttSubscriber : MqttCallbackExtended {
|
||||
private val broker = "tcp://mqtt.k8s.kmlabz.com:1883"
|
||||
private val clientId = MqttClient.generateClientId()
|
||||
private val persistence = MemoryPersistence()
|
||||
private val mqttClient = MqttAsyncClient(broker, clientId, persistence)
|
||||
private val mqttClient = MqttClient(broker, clientId, persistence)
|
||||
private val benchValues = HashMap<Int, Instant>()
|
||||
|
||||
override fun connectionLost(arg0: Throwable) {
|
||||
@ -25,10 +25,12 @@ class MqttSubscriber : MqttCallbackExtended {
|
||||
}
|
||||
|
||||
override fun connectComplete(reconnect: Boolean, serverURI: String?) {
|
||||
println("Subscribing to all topics")
|
||||
mqttClient.subscribe("#", 0)
|
||||
}
|
||||
|
||||
fun connect() {
|
||||
println("Connecting to broker")
|
||||
val connOpts = MqttConnectOptions()
|
||||
connOpts.isCleanSession = true
|
||||
connOpts.userName = "birbnetes"
|
||||
@ -38,6 +40,7 @@ class MqttSubscriber : MqttCallbackExtended {
|
||||
}
|
||||
|
||||
fun disconnect(): HashMap<Int, Instant> {
|
||||
println("Disconnecting from broker")
|
||||
mqttClient.disconnect()
|
||||
mqttClient.close()
|
||||
return benchValues
|
||||
|
Loading…
Reference in New Issue
Block a user