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;
}
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);
}
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);
}
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();
}
Aggregations