Search in sources :

Example 1 with MqttServerOptions

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());
        }
    });
}
Also used : MqttServerOptions(io.vertx.mqtt.MqttServerOptions) MqttServer(io.vertx.mqtt.MqttServer)

Example 2 with MqttServerOptions

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();
    }
}
Also used : MqttServerOptions(io.vertx.mqtt.MqttServerOptions)

Example 3 with MqttServerOptions

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());
        }
    });
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) MqttServerOptions(io.vertx.mqtt.MqttServerOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) Runner(io.vertx.example.mqtt.util.Runner) MqttServer(io.vertx.mqtt.MqttServer) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) MqttServerOptions(io.vertx.mqtt.MqttServerOptions) MqttServer(io.vertx.mqtt.MqttServer)

Example 4 with MqttServerOptions

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);
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) MqttServerOptions(io.vertx.mqtt.MqttServerOptions) Router(io.vertx.ext.web.Router)

Example 5 with MqttServerOptions

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();
    }
}
Also used : MqttServerOptions(io.vertx.mqtt.MqttServerOptions)

Aggregations

MqttServerOptions (io.vertx.mqtt.MqttServerOptions)5 PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)2 MqttServer (io.vertx.mqtt.MqttServer)2 AbstractVerticle (io.vertx.core.AbstractVerticle)1 Runner (io.vertx.example.mqtt.util.Runner)1 Router (io.vertx.ext.web.Router)1