use of org.apache.storm.mqtt.MqttLogger in project storm by apache.
the class MqttUtils method configureClient.
public static MQTT configureClient(MqttOptions options, String clientId, KeyStoreLoader keyStoreLoader) throws Exception {
MQTT client = new MQTT();
URI uri = URI.create(options.getUrl());
client.setHost(uri);
if (!uri.getScheme().toLowerCase().equals("tcp")) {
client.setSslContext(SslUtils.sslContext(uri.getScheme(), keyStoreLoader));
}
client.setClientId(clientId);
LOG.info("MQTT ClientID: {}", client.getClientId().toString());
client.setCleanSession(options.isCleanConnection());
client.setReconnectDelay(options.getReconnectDelay());
client.setReconnectDelayMax(options.getReconnectDelayMax());
client.setReconnectBackOffMultiplier(options.getReconnectBackOffMultiplier());
client.setConnectAttemptsMax(options.getConnectAttemptsMax());
client.setReconnectAttemptsMax(options.getReconnectAttemptsMax());
client.setUserName(options.getUserName());
client.setPassword(options.getPassword());
client.setTracer(new MqttLogger());
if (options.getWillTopic() != null && options.getWillPayload() != null) {
QoS qos = MqttUtils.qosFromInt(options.getWillQos());
client.setWillQos(qos);
client.setWillTopic(options.getWillTopic());
client.setWillMessage(options.getWillPayload());
client.setWillRetain(options.getWillRetain());
}
return client;
}
use of org.apache.storm.mqtt.MqttLogger in project storm by apache.
the class MqttBrokerPublisher method startPublisher.
/**
* Initializes {@code connection}.
* @throws Exception if an exception during connecting to connector occurs
*/
public static void startPublisher() throws Exception {
MQTT client = new MQTT();
client.setTracer(new MqttLogger());
client.setHost("tcp://localhost:1883");
client.setClientId("MqttBrokerPublisher");
connection = client.blockingConnection();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
LOG.info("Shutting down MQTT client...");
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
});
connection.connect();
}
Aggregations