1 Star 0 Fork 1

光魔科技/vertx-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client.rb 621 Bytes
一键复制 编辑 原始数据 按行查看 历史
Julien Viet 提交于 2018-02-04 14:53 . Update for 3.5.1 staging
require 'vertx-mqtt/mqtt_client'
require 'vertx/buffer'
@MQTT_MESSAGE = "Hello Vert.x MQTT Client"
@BROKER_HOST = "localhost"
@BROKER_PORT = 1883
@MQTT_TOPIC = "/my_topic"
mqttClient = VertxMqtt::MqttClient.create($vertx)
mqttClient.connect(@BROKER_PORT, @BROKER_HOST) { |ch_err,ch|
if (ch_err == nil)
puts "Connected to a server"
mqttClient.publish(@MQTT_TOPIC, Vertx::Buffer.buffer(@MQTT_MESSAGE), :AT_MOST_ONCE, false, false) { |s_err,s|
mqttClient.disconnect() { |d_err,d|
puts "Disconnected from server"
}
}
else
puts "Failed to connect to a server"
puts ch_err
end
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/3kgz/vertx-examples.git
git@gitee.com:3kgz/vertx-examples.git
3kgz
vertx-examples
vertx-examples
master

搜索帮助