forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.kt
36 lines (26 loc) · 939 Bytes
/
Server.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.vertx.example.mqtt.simple
import io.vertx.kotlin.mqtt.*
import io.vertx.mqtt.MqttServer
import io.vertx.mqtt.MqttServerOptions
class Server : io.vertx.core.AbstractVerticle() {
override fun start() {
var options = MqttServerOptions(
port = 1883,
host = "0.0.0.0")
var server = MqttServer.create(vertx, options)
server.endpointHandler({ endpoint ->
println("connected client ${endpoint.clientIdentifier()}")
endpoint.publishHandler({ message ->
println("Just received message on [${message.topicName()}] payload [${message.payload()}] with QoS [${message.qosLevel()}]")
})
endpoint.accept(false)
})
server.listen({ ar ->
if (ar.succeeded()) {
println("MQTT server started and listening on port ${server.actualPort()}")
} else {
System.err.println("MQTT server error on start${ar.cause().getMessage()}")
}
})
}
}