Skip to content

Commit

Permalink
use-ssl mqtt option
Browse files Browse the repository at this point in the history
  • Loading branch information
Randall Raboy committed Apr 7, 2023
1 parent 91032cc commit f644cc7
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public MqttClient getMqttClient(@Value("${dirigera.mqtt.hostname:localhost}") fi
@Value("${dirigera.mqtt.port:1883}") final Short port,
@Value("${dirigera.mqtt.username:}") final String username,
@Value("${dirigera.mqtt.password:}") final String password,
@Value("${dirigera.mqtt.use-ssl:false}") final Boolean useSsl,
@Value("${dirigera.mqtt.reconnect:true}") final Boolean reconnect,
@Value("${dirigera.mqtt.timeout:0}") final Integer timeout,
@Value("${dirigera.mqtt.keep-alive:2}") final Integer keepAliveInterval,
Expand All @@ -55,7 +56,7 @@ public MqttClient getMqttClient(@Value("${dirigera.mqtt.hostname:localhost}") fi
publisherId = api.status().map(s -> s.id).block();
options = new MqttConnectOptions();

if (port == 8883) {
if (useSsl) {
uri = String.format("ssl://%s:%d", host, port);
options.setSocketFactory(SSLSocketFactory.getDefault());
} else {
Expand All @@ -64,8 +65,8 @@ public MqttClient getMqttClient(@Value("${dirigera.mqtt.hostname:localhost}") fi

client = new MqttClient(uri, publisherId);

log.info("Connect to MQTT broker: host={}, port={}, publisherId={}, reconnect={}, timeout={}",
host, port, publisherId, reconnect, timeout);
log.info("Connect to MQTT broker: host={}, port={}, publisherId={}, reconnect={}, timeout={}, useSsl={}",
host, port, publisherId, reconnect, timeout, useSsl);

options.setKeepAliveInterval(keepAliveInterval);
options.setMaxReconnectDelay(reconnectDelay);
Expand Down

0 comments on commit f644cc7

Please sign in to comment.