Search in sources :

Example 1 with Mqtt3ConnectBuilder

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());
}
Also used : Mqtt3ConnectBuilder(com.hivemq.client.mqtt.mqtt3.message.connect.Mqtt3ConnectBuilder) Mqtt3Publish(com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish)

Aggregations

Mqtt3ConnectBuilder (com.hivemq.client.mqtt.mqtt3.message.connect.Mqtt3ConnectBuilder)1 Mqtt3Publish (com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish)1