@Override
public void connectToExternal() throws ComponentException {
MemoryPersistence persistence = new MemoryPersistence();
final MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
try {
mqttClient = new MqttAsyncClient(componentConfig.getExternalConnectionString(), getId(), persistence);
mqttClient.connect(options, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
LOGGER.info( getName() + " connected to " + componentConfig.getExternalConnectionString());
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
LOGGER.info( getName() + " could not establish connection to " + componentConfig.getExternalConnectionString());
}
}).waitForCompletion();
} catch (MqttException e) {
throw new ComponentException( getName() + " cannot connect to \"" + componentConfig.getExternalConnectionString() + "\"", e);
}
}