use of com.hivemq.client.mqtt.mqtt3.message.connect.Mqtt3ConnectBuilder in project openhab-core by openhab.
the class Mqtt3AsyncClientWrapper method connect.
@Override
public CompletableFuture<?> connect(@Nullable MqttWillAndTestament lwt, int keepAliveInterval, @Nullable String username, @Nullable String password) {
Mqtt3ConnectBuilder connectMessageBuilder = Mqtt3Connect.builder().keepAlive(keepAliveInterval);
if (lwt != null) {
Mqtt3Publish willPublish = Mqtt3Publish.builder().topic(lwt.getTopic()).payload(lwt.getPayload()).retain(lwt.isRetain()).qos(getMqttQosFromInt(lwt.getQos())).build();
connectMessageBuilder.willPublish(willPublish);
}
if (username != null && !username.isBlank() && password != null && !password.isBlank()) {
connectMessageBuilder.simpleAuth().username(username).password(password.getBytes()).applySimpleAuth();
}
return client.connect(connectMessageBuilder.build());
}
Aggregations