Skip to content

Commit

Permalink
Basic MQTTS support
Browse files Browse the repository at this point in the history
  • Loading branch information
Randall Raboy committed Mar 18, 2023
1 parent 8f17499 commit 91032cc
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import javax.net.ssl.SSLSocketFactory;

@SpringBootApplication
@ComponentScan(basePackageClasses = {
Expand Down Expand Up @@ -52,13 +53,20 @@ public MqttClient getMqttClient(@Value("${dirigera.mqtt.hostname:localhost}") fi
final String uri;

publisherId = api.status().map(s -> s.id).block();
uri = String.format("tcp://%s:%d", host, port);
options = new MqttConnectOptions();

if (port == 8883) {
uri = String.format("ssl://%s:%d", host, port);
options.setSocketFactory(SSLSocketFactory.getDefault());
} else {
uri = String.format("tcp://%s:%d", host, port);
}

client = new MqttClient(uri, publisherId);

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

options = new MqttConnectOptions();
options.setKeepAliveInterval(keepAliveInterval);
options.setMaxReconnectDelay(reconnectDelay);
options.setAutomaticReconnect(reconnect);
Expand Down

0 comments on commit 91032cc

Please sign in to comment.