1 Star 0 Fork 1

光魔科技/vertx-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Client.kt 870 Bytes
一键复制 编辑 原始数据 按行查看 历史
Julien Viet 提交于 2017-09-15 11:19 . Regen code
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())
}
})
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/3kgz/vertx-examples.git
git@gitee.com:3kgz/vertx-examples.git
3kgz
vertx-examples
vertx-examples
master

搜索帮助