代码拉取完成,页面将自动刷新
package io.vertx.example.mqtt.simple
import io.netty.handler.codec.mqtt.MqttQoS
import io.vertx.core.buffer.Buffer
import io.vertx.mqtt.MqttClient
class Client : io.vertx.core.AbstractVerticle() {
var MQTT_MESSAGE = "Hello Vert.x MQTT Client"
var BROKER_HOST = "localhost"
var BROKER_PORT = 1883
var MQTT_TOPIC = "/my_topic"
override fun start() {
var mqttClient = MqttClient.create(vertx)
mqttClient.connect(BROKER_PORT, BROKER_HOST, { ch ->
if (ch.succeeded()) {
println("Connected to a server")
mqttClient.publish(MQTT_TOPIC, Buffer.buffer(MQTT_MESSAGE), MqttQoS.AT_MOST_ONCE, false, false, { s ->
mqttClient.disconnect({ d ->
println("Disconnected from server")
})
})
} else {
println("Failed to connect to a server")
println(ch.cause())
}
})
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。