Search in sources :

Example 1 with MemoryConfig

use of io.moquette.server.config.MemoryConfig in project nifi by apache.

the class TestConsumeMQTT method startServer.

private void startServer() throws IOException {
    MQTT_server = new Server();
    final Properties configProps = new Properties();
    configProps.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, "1884");
    configProps.setProperty(PERSISTENT_STORE_PROPERTY_NAME, "./target/moquette_store.mapdb");
    IConfig server_config = new MemoryConfig(configProps);
    MQTT_server.startServer(server_config);
}
Also used : IConfig(io.moquette.server.config.IConfig) Server(io.moquette.server.Server) MemoryConfig(io.moquette.server.config.MemoryConfig) Properties(java.util.Properties)

Example 2 with MemoryConfig

use of io.moquette.server.config.MemoryConfig in project nifi by apache.

the class TestPublishAndSubscribeMqttIntegration method startServer.

private void startServer() throws IOException {
    MQTT_server = new Server();
    final Properties configProps = new Properties();
    configProps.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, "1884");
    configProps.setProperty(PERSISTENT_STORE_PROPERTY_NAME, "./target/moquette_store.mapdb");
    IConfig server_config = new MemoryConfig(configProps);
    MQTT_server.startServer(server_config);
}
Also used : IConfig(io.moquette.server.config.IConfig) Server(io.moquette.server.Server) MemoryConfig(io.moquette.server.config.MemoryConfig) Properties(java.util.Properties)

Example 3 with MemoryConfig

use of io.moquette.server.config.MemoryConfig in project nifi by apache.

the class TestPublishMqttSSL method startServer.

private void startServer() throws IOException {
    MQTT_server = new Server();
    final Properties configProps = new Properties();
    configProps.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, "1884");
    configProps.put(BrokerConstants.SSL_PORT_PROPERTY_NAME, "8883");
    configProps.put(BrokerConstants.JKS_PATH_PROPERTY_NAME, "src/test/resources/localhost-ks.jks");
    configProps.put(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME, "localtest");
    configProps.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "localtest");
    configProps.setProperty(PERSISTENT_STORE_PROPERTY_NAME, "./target/moquette_store.mapdb");
    IConfig server_config = new MemoryConfig(configProps);
    MQTT_server.startServer(server_config);
}
Also used : IConfig(io.moquette.server.config.IConfig) Server(io.moquette.server.Server) MemoryConfig(io.moquette.server.config.MemoryConfig) Properties(java.util.Properties) MqttTestUtils.createSslProperties(org.apache.nifi.processors.mqtt.common.MqttTestUtils.createSslProperties)

Example 4 with MemoryConfig

use of io.moquette.server.config.MemoryConfig in project smarthome by eclipse.

the class EmbeddedBrokerServiceImpl method startEmbeddedServer.

@Override
public void startEmbeddedServer(@Nullable Integer portParam, boolean secure, @Nullable String username, @Nullable String password, String persistenceFilenameParam) throws IOException {
    String persistenceFilename = persistenceFilenameParam;
    Server server = new Server();
    Properties properties = new Properties();
    // Host and port
    properties.put(BrokerConstants.HOST_PROPERTY_NAME, "0.0.0.0");
    int port;
    if (secure) {
        port = (portParam == null) ? port = 8883 : portParam;
        properties.put(BrokerConstants.SSL_PORT_PROPERTY_NAME, Integer.toString(port));
        properties.put(BrokerConstants.PORT_PROPERTY_NAME, BrokerConstants.DISABLED_PORT_BIND);
        properties.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "esheshesh");
    } else {
        port = (portParam == null) ? port = 1883 : portParam;
        // with SSL_PORT_PROPERTY_NAME set, netty tries to evaluate the SSL context and shuts down immediately.
        // properties.put(BrokerConstants.SSL_PORT_PROPERTY_NAME, BrokerConstants.DISABLED_PORT_BIND);
        properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(port));
    }
    // Authentication
    io.moquette.spi.security.IAuthenticator authentificator = null;
    if (username != null && password != null && username.length() > 0 && password.length() > 0) {
        properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, false);
        properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, MqttEmbeddedBrokerUserAuthenticator.class.getName());
        authentificator = new MqttEmbeddedBrokerUserAuthenticator(username, password.getBytes());
    } else {
        properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
    }
    // Persistence: If not set, an in-memory database is used.
    if (!persistenceFilename.isEmpty()) {
        if (!Paths.get(persistenceFilename).isAbsolute()) {
            persistenceFilename = Paths.get(ConfigConstants.getUserDataFolder()).toAbsolutePath().resolve(persistenceFilename).toString();
        }
        properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, persistenceFilename);
    }
    // We may provide ACL functionality at some point as well
    IAuthorizator authorizer = null;
    // Secure connection support
    // TODO wait for NetworkServerTls implementation
    // try {
    // final SSLContext sslContext = networkServerTls.createSSLContext("mqtt");
    // server.startServer(new MemoryConfig(properties), null, () -> sslContext, authentificator, authorizer);
    // } catch (GeneralSecurityException | IOException e) {
    // logger.error("No SSL available", e);
    server.startServer(new MemoryConfig(properties), null, null, authentificator, authorizer);
    // }
    this.server = server;
    metrics.setServer(server);
    ScheduledExecutorService s = new ScheduledThreadPoolExecutor(1);
    detectStart.startBrokerStartedDetection(port, s);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Server(io.moquette.server.Server) MemoryConfig(io.moquette.server.config.MemoryConfig) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) IAuthorizator(io.moquette.spi.security.IAuthorizator) Properties(java.util.Properties)

Example 5 with MemoryConfig

use of io.moquette.server.config.MemoryConfig in project nifi by apache.

the class TestConsumeMqttSSL method startServer.

private void startServer() throws IOException {
    MQTT_server = new Server();
    final Properties configProps = new Properties();
    configProps.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, "1884");
    configProps.put(BrokerConstants.SSL_PORT_PROPERTY_NAME, "8883");
    configProps.put(BrokerConstants.JKS_PATH_PROPERTY_NAME, "src/test/resources/localhost-ks.jks");
    configProps.put(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME, "localtest");
    configProps.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "localtest");
    configProps.setProperty(PERSISTENT_STORE_PROPERTY_NAME, "./target/moquette_store.mapdb");
    IConfig server_config = new MemoryConfig(configProps);
    MQTT_server.startServer(server_config);
}
Also used : IConfig(io.moquette.server.config.IConfig) Server(io.moquette.server.Server) MemoryConfig(io.moquette.server.config.MemoryConfig) MqttTestUtils.createSslProperties(org.apache.nifi.processors.mqtt.common.MqttTestUtils.createSslProperties) Properties(java.util.Properties)

Aggregations

Server (io.moquette.server.Server)6 MemoryConfig (io.moquette.server.config.MemoryConfig)6 Properties (java.util.Properties)6 IConfig (io.moquette.server.config.IConfig)5 MqttTestUtils.createSslProperties (org.apache.nifi.processors.mqtt.common.MqttTestUtils.createSslProperties)2 IAuthorizator (io.moquette.spi.security.IAuthorizator)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1