Search in sources :

Example 6 with Server

use of io.moquette.server.Server in project mist by snuspl.

the class MqttUtils method createMqttBroker.

/**
 * Create an Mqtt broker.
 * @return mqtt broker
 * @throws java.io.IOException
 */
public static Server createMqttBroker() throws IOException {
    // Create tmp folder
    final File tmpDir = new File(TMP_DIR);
    if (!tmpDir.exists()) {
        System.out.println("creating directory: " + tmpDir.getName());
        boolean result = false;
        try {
            tmpDir.mkdir();
            result = true;
        } catch (final SecurityException se) {
        // do nothing
        }
        if (result) {
            System.out.println(tmpDir.getName() + " created");
        }
    }
    // create local mqtt broker
    final Properties brokerProps = new Properties();
    brokerProps.put("port", PORT);
    brokerProps.put("host", HOST);
    brokerProps.put("websocket_port", WEBSOKET_PORT);
    brokerProps.put("allow_anonymous", "true");
    brokerProps.put("persistent_store", new StringBuilder().append(DIR_PATH_PREFIX).append((Long) System.currentTimeMillis()).append(".mapdb").toString());
    final Server mqttBroker = new Server();
    mqttBroker.startServer(brokerProps);
    return mqttBroker;
}
Also used : Server(io.moquette.server.Server) Properties(java.util.Properties) File(java.io.File)

Example 7 with Server

use of io.moquette.server.Server 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)

Example 8 with Server

use of io.moquette.server.Server in project nifi by apache.

the class TestPublishMQTT 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 9 with Server

use of io.moquette.server.Server in project mist by snuspl.

the class PhysicalObjectGeneratorTest method testSuccessOfMqttSink.

/**
 * Test if the mqtt sink is created successfully.
 */
@Test
public void testSuccessOfMqttSink() throws IOException, InjectionException {
    final Server mqttBroker = MqttUtils.createMqttBroker();
    final String topic = "mqttTest";
    final Map<String, String> conf = new HashMap<String, String>() {

        {
            put(ConfKeys.SinkConf.SINK_TYPE.name(), ConfValues.SinkType.MQTT.name());
            put(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name(), MqttUtils.BROKER_URI);
            put(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name(), topic);
        }
    };
    final Sink sink = generator.newSink(conf, classLoader);
    Assert.assertTrue(sink instanceof MqttSink);
    mqttBroker.stopServer();
}
Also used : MqttSink(edu.snu.mist.core.sinks.MqttSink) Server(io.moquette.server.Server) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Sink(edu.snu.mist.core.sinks.Sink) MqttSink(edu.snu.mist.core.sinks.MqttSink) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Server (io.moquette.server.Server)9 Properties (java.util.Properties)7 MemoryConfig (io.moquette.server.config.MemoryConfig)6 IConfig (io.moquette.server.config.IConfig)5 MqttTestUtils.createSslProperties (org.apache.nifi.processors.mqtt.common.MqttTestUtils.createSslProperties)2 Test (org.junit.Test)2 MqttSink (edu.snu.mist.core.sinks.MqttSink)1 NettyTextSink (edu.snu.mist.core.sinks.NettyTextSink)1 Sink (edu.snu.mist.core.sinks.Sink)1 IAuthorizator (io.moquette.spi.security.IAuthorizator)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 Tuple (org.apache.reef.io.Tuple)1 MqttClient (org.eclipse.paho.client.mqttv3.MqttClient)1 MqttException (org.eclipse.paho.client.mqttv3.MqttException)1 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)1