use of com.hivemq.client.mqtt.MqttClientSslConfig in project open-smart-grid-platform by OSGP.
the class Simulator method main.
public static void main(final String[] args) throws IOException {
final String spec = getFirstArgOrNull(args);
final Properties sslServerProperties = new Properties();
final MqttClientSslConfig sslClientProperties = null;
final boolean startClient = getSecondArgOrTrue(args);
final Simulator app = new Simulator();
app.run(spec, startClient, sslServerProperties, sslClientProperties);
}
use of com.hivemq.client.mqtt.MqttClientSslConfig in project open-smart-grid-platform by OSGP.
the class MqttDeviceSteps method startPublishingClient.
private void startPublishingClient(final String host, final int port, final String topic, final String payload, final Map<String, String> parameters) {
final SimulatorSpec spec = new SimulatorSpec(host, port);
spec.setStartupPauseMillis(2000);
final Message message = new Message(topic, payload, 10000);
final Message[] messages = { message };
spec.setMessages(messages);
MqttClientSslConfig mqttClientSslConfig = null;
final boolean mqttSslEnabled = ReadSettingsHelper.getBoolean(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_ENABLED, PlatformDistributionAutomationDefaults.MQTT_SSL_ENABLED);
if (mqttSslEnabled) {
final String truststoreLocation = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_LOCATION, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_LOCATION);
final String truststorePassword = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_PASSWORD, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_PASSWORD);
final String truststoreType = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_TYPE, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_TYPE);
final ResourceLoader resourceLoader = new DefaultResourceLoader();
final Resource trustStoreResource = resourceLoader.getResource(truststoreLocation);
mqttClientSslConfig = MqttClientSslConfigFactory.getMqttClientSslConfig(trustStoreResource, truststorePassword, truststoreType);
}
final SimulatorSpecPublishingClient publishingClient = new SimulatorSpecPublishingClient(spec, mqttClientSslConfig);
publishingClient.start();
}
use of com.hivemq.client.mqtt.MqttClientSslConfig in project open-smart-grid-platform by OSGP.
the class MqttClient method createClient.
private Mqtt3AsyncClient createClient(final MqttClientDefaults mqttClientDefaults, final MqttClientSslConfig mqttClientSslConfig, final String clientIdentifier) {
Mqtt3ClientBuilder clientBuilder = Mqtt3Client.builder().identifier(clientIdentifier).serverHost(mqttClientDefaults.getDefaultHost()).serverPort(mqttClientDefaults.getDefaultPort()).sslConfig(mqttClientSslConfig).automaticReconnectWithDefaultConfig().addConnectedListener(context -> LOGGER.info("{} client {} connected to broker at {}:{}", context.getClientConfig().getMqttVersion(), context.getClientConfig().getClientIdentifier().map(MqttClientIdentifier::toString).orElse(clientIdentifier), context.getClientConfig().getServerHost(), context.getClientConfig().getServerPort())).addDisconnectedListener(context -> LOGGER.info("{} client {} disconnected from broker at {}:{}", context.getClientConfig().getMqttVersion(), context.getClientConfig().getClientIdentifier().map(MqttClientIdentifier::toString).orElse(clientIdentifier), context.getClientConfig().getServerHost(), context.getClientConfig().getServerPort()));
if (StringUtils.isNotEmpty(mqttClientDefaults.getDefaultUsername())) {
LOGGER.debug("Using username/password for MQTT connection");
clientBuilder = clientBuilder.simpleAuth().username(mqttClientDefaults.getDefaultUsername()).password(mqttClientDefaults.getDefaultPassword().getBytes()).applySimpleAuth();
}
return clientBuilder.buildAsync();
}
Aggregations