Erweiterungen
This commit is contained in:
@@ -48,15 +48,12 @@ public class MqttV5ClientManager implements SmartLifecycle {
|
||||
String clientId = buildClientId(props.getClientId());
|
||||
URI uri = URI.create(props.getBrokerUri());
|
||||
String host = uri.getHost();
|
||||
int port = uri.getPort() > 0 ? uri.getPort() : ("ssl".equalsIgnoreCase(uri.getScheme()) || "mqtts".equalsIgnoreCase(uri.getScheme()) ? 8883 : 1883);
|
||||
int port = 42099;
|
||||
|
||||
var builder = Mqtt5Client.builder()
|
||||
.identifier(clientId)
|
||||
.serverHost(host)
|
||||
.serverPort(port);
|
||||
if ("ssl".equalsIgnoreCase(uri.getScheme()) || "mqtts".equalsIgnoreCase(uri.getScheme()) || "tls".equalsIgnoreCase(uri.getScheme())) {
|
||||
builder = builder.sslWithDefaultConfig();
|
||||
}
|
||||
if (props.isAutomaticReconnect()) {
|
||||
builder = builder.automaticReconnectWithDefaultConfig();
|
||||
}
|
||||
@@ -65,7 +62,11 @@ public class MqttV5ClientManager implements SmartLifecycle {
|
||||
var connect = client.connectWith()
|
||||
.cleanStart(props.isCleanStart())
|
||||
.keepAlive(props.getKeepAlive())
|
||||
.sessionExpiryInterval(props.getSessionExpiryInterval());
|
||||
.sessionExpiryInterval(props.getSessionExpiryInterval())
|
||||
.simpleAuth()
|
||||
.username("app")
|
||||
.password("apppwd".getBytes(StandardCharsets.UTF_8))
|
||||
.applySimpleAuth();
|
||||
|
||||
log.info("[MQTT] Connecting to {} with clientId={} ...", props.getBrokerUri(), clientId);
|
||||
connect.send().join();
|
||||
|
||||
@@ -42,7 +42,8 @@ spring.jackson.default-property-inclusion=non_null
|
||||
|
||||
# MQTT v5 settings
|
||||
app.mqtt.enabled=true
|
||||
app.mqtt.broker-uri=tcp://192.168.180.26:1883
|
||||
#app.mqtt.broker-uri=mqtt://192.168.180.26:1883
|
||||
app.mqtt.broker-uri=mqtt://mqtt-2.assecutor.de
|
||||
# The server MQTT clientId; a random UUID suffix will be inserted where ${random.uuid} appears
|
||||
app.mqtt.client-id=server-${random.uuid}
|
||||
# v5 session and keepalive
|
||||
|
||||
Reference in New Issue
Block a user