use of io.vertx.mqtt.MqttServerOptions in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
MqttServerOptions options = new MqttServerOptions().setPort(1883).setHost("0.0.0.0");
MqttServer server = MqttServer.create(vertx, options);
server.endpointHandler(endpoint -> {
System.out.println("connected client " + endpoint.clientIdentifier());
endpoint.publishHandler(message -> {
System.out.println("Just received message on [" + message.topicName() + "] payload [" + message.payload() + "] with QoS [" + message.qosLevel() + "]");
});
endpoint.accept(false);
});
server.listen(ar -> {
if (ar.succeeded()) {
System.out.println("MQTT server started and listening on port " + server.actualPort());
} else {
System.err.println("MQTT server error on start" + ar.cause().getMessage());
}
});
}
use of io.vertx.mqtt.MqttServerOptions in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapter method bindInsecureMqttServer.
private Future<Void> bindInsecureMqttServer() {
if (isInsecurePortEnabled()) {
final MqttServerOptions options = new MqttServerOptions();
options.setHost(getConfig().getInsecurePortBindAddress()).setPort(determineInsecurePort()).setMaxMessageSize(getConfig().getMaxPayloadSize() + MAX_MSG_SIZE_VARIABLE_HEADER_SIZE);
return bindMqttServer(options, insecureServer).map(createdServer -> {
insecureServer = createdServer;
return (Void) null;
});
} else {
return Future.succeededFuture();
}
}
use of io.vertx.mqtt.MqttServerOptions in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
MqttServerOptions options = new MqttServerOptions().setPort(8883).setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem")).setSsl(true);
MqttServer mqttServer = MqttServer.create(vertx, options);
mqttServer.endpointHandler(endpoint -> {
// shows main connect info
System.out.println("MQTT client [" + endpoint.clientIdentifier() + "] request to connect, " + "clean session = " + endpoint.isCleanSession());
// accept connection from the remote client
endpoint.accept(false);
}).listen(ar -> {
if (ar.succeeded()) {
System.out.println("MQTT server is listening on port " + mqttServer.actualPort());
} else {
System.err.println("Error on starting the server" + ar.cause().getMessage());
}
});
}
use of io.vertx.mqtt.MqttServerOptions in project vertx-openshift-it by cescoffier.
the class MqttBroker method start.
@Override
public void start() {
MqttServerOptions options = new MqttServerOptions().setKeyCertOptions(new PemKeyCertOptions().setKeyPath("private.pem").setCertPath("public.pem")).setSsl(true).setPort(8883);
MqttServer.create(vertx, options).endpointHandler(this::configureEndpoint).listen(start -> {
if (start.succeeded()) {
System.out.println("MQTT secured server is listening on port " + start.result().actualPort());
} else {
System.out.println("Error on starting the secured server");
start.cause().printStackTrace();
}
});
MqttServer.create(vertx).endpointHandler(this::configureEndpoint).listen(start -> {
if (start.succeeded()) {
System.out.println("MQTT insecure server is listening on port " + start.result().actualPort());
} else {
System.out.println("Error on starting the insecure server");
start.cause().printStackTrace();
}
});
// Just for healthcheck purposes
Router router = Router.router(vertx);
router.get("/").handler(this::healthcheck);
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
use of io.vertx.mqtt.MqttServerOptions in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapter method bindSecureMqttServer.
private Future<Void> bindSecureMqttServer() {
if (isSecurePortEnabled()) {
final MqttServerOptions options = new MqttServerOptions();
options.setHost(getConfig().getBindAddress()).setPort(determineSecurePort()).setMaxMessageSize(getConfig().getMaxPayloadSize() + MAX_MSG_SIZE_VARIABLE_HEADER_SIZE);
addTlsKeyCertOptions(options);
addTlsTrustOptions(options);
return bindMqttServer(options, server).map(s -> {
server = s;
return (Void) null;
});
} else {
return Future.succeededFuture();
}
}
Aggregations