Interface Mqtt5AsyncClient
- All Superinterfaces:
Mqtt5Client,MqttClient
Mqtt5Client based on futures and callbacks.- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder for aMqtt5Subscribeand additional arguments that are applied to asubscribe(Mqtt5Subscribe),subscribe(Mqtt5Subscribe, Consumer, boolean)orsubscribe(Mqtt5Subscribe, Consumer, Executor, boolean)call. -
Field Summary
Fields inherited from interface com.hivemq.client.mqtt.MqttClient
DEFAULT_SERVER_HOST, DEFAULT_SERVER_PORT, DEFAULT_SERVER_PORT_SSL, DEFAULT_SERVER_PORT_WEBSOCKET, DEFAULT_SERVER_PORT_WEBSOCKET_SSL -
Method Summary
Modifier and TypeMethodDescriptionconnect()Connects this client with the default Connect message.connect(@NotNull Mqtt5Connect connect) Connects this client with the given Connect message.Fluent counterpart ofconnect(Mqtt5Connect).Disconnects this client with the default Disconnect message.disconnect(@NotNull Mqtt5Disconnect disconnect) Disconnects this client with the given Disconnect message.Fluent counterpart ofdisconnect(Mqtt5Disconnect).publish(@NotNull Mqtt5Publish publish) Publishes the given Publish message.voidpublishes(@NotNull MqttGlobalPublishFilter filter, @NotNull Consumer<@NotNull Mqtt5Publish> callback) Globally consumes all incoming Publish messages matching the given filter.voidpublishes(@NotNull MqttGlobalPublishFilter filter, @NotNull Consumer<@NotNull Mqtt5Publish> callback, boolean manualAcknowledgement) Globally consumes all incoming Publish messages matching the given filter.voidpublishes(@NotNull MqttGlobalPublishFilter filter, @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull Executor executor) Globally consumes all incoming Publish messages matching the given filter.voidpublishes(@NotNull MqttGlobalPublishFilter filter, @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull Executor executor, boolean manualAcknowledgement) Globally consumes all incoming Publish messages matching the given filter.Fluent counterpart ofpublish(Mqtt5Publish).reauth()Re-authenticates this client.subscribe(@NotNull Mqtt5Subscribe subscribe) Subscribes this client with the given Subscribe message.subscribe(@NotNull Mqtt5Subscribe subscribe, @NotNull Consumer<@NotNull Mqtt5Publish> callback) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.subscribe(@NotNull Mqtt5Subscribe subscribe, @NotNull Consumer<@NotNull Mqtt5Publish> callback, boolean manualAcknowledgement) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.subscribe(@NotNull Mqtt5Subscribe subscribe, @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull Executor executor) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.subscribe(@NotNull Mqtt5Subscribe subscribe, @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull Executor executor, boolean manualAcknowledgement) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.default @NotNull Mqtt5AsyncClienttoAsync()Turns the API of this client into a asynchronous API based on futures and callbacks.unsubscribe(@NotNull Mqtt5Unsubscribe unsubscribe) Unsubscribes this client with the given Unsubscribe message.Fluent counterpart ofunsubscribe(Mqtt5Unsubscribe).Methods inherited from interface com.hivemq.client.mqtt.mqtt5.Mqtt5Client
getConfig, toBlocking, toRxMethods inherited from interface com.hivemq.client.mqtt.MqttClient
getState
-
Method Details
-
connect
Connects this client with the default Connect message.- Returns:
- see
connect(Mqtt5Connect). - See Also:
-
connect
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5ConnAck> connect(@NotNull @NotNull Mqtt5Connect connect) Connects this client with the given Connect message.- Parameters:
connect- the Connect message sent to the broker.- Returns:
- a
CompletableFuturewhich- completes normally with the ConnAck message if it does not contain an Error Code (connected successfully),
- completes exceptionally with a
Mqtt5ConnAckExceptionwrapping the ConnAck message if it contains an Error Code or - completes exceptionally with a different exception if an error occurred before the Connect message was sent or before the ConnAck message was received.
-
connectWith
Fluent counterpart ofconnect(Mqtt5Connect).Calling
Mqtt5ConnectBuilder.Send.send()on the returned builder has the same effect as callingconnect(Mqtt5Connect)with the result ofMqtt5ConnectBuilder.build().- Returns:
- the fluent builder for the Connect message.
- See Also:
-
subscribe
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5SubAck> subscribe(@NotNull @NotNull Mqtt5Subscribe subscribe) Subscribes this client with the given Subscribe message.See
publishes(MqttGlobalPublishFilter, Consumer)orpublishes(MqttGlobalPublishFilter, Consumer, Executor)to consume the incoming Publish messages. Alternatively, callsubscribe(Mqtt5Subscribe, Consumer)orsubscribe(Mqtt5Subscribe, Consumer, Executor)to consume the incoming Publish messages matching the subscriptions of the Subscribe message directly.- Parameters:
subscribe- the Subscribe messages sent to the broker.- Returns:
- a
CompletableFuturewhich- completes normally with the SubAck message if all subscriptions of the Subscribe message were successful (the SubAck message contains no Error Codes),
- completes exceptionally with a
Mqtt5SubAckExceptionwrapping the SubAck message if it contains at least one Error Code or - completes exceptionally with a different exception if an error occurred before the Subscribe message was sent or before a SubAck message was received.
-
subscribe
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5SubAck> subscribe(@NotNull @NotNull Mqtt5Subscribe subscribe, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.- Parameters:
subscribe- the Subscribe messages sent to the broker.callback- the callback for consuming the incoming Publish messages matching the subscriptions of the Subscribe message.- Returns:
- see
subscribe(Mqtt5Subscribe). - See Also:
-
subscribe
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5SubAck> subscribe(@NotNull @NotNull Mqtt5Subscribe subscribe, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull @NotNull Executor executor) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.The future is completed and the callback is executed on the given executor.
- Parameters:
subscribe- the Subscribe messages sent to the broker.callback- the callback for consuming the incoming Publish messages matching the subscriptions of the Subscribe message.executor- the executor where the future is completed and the callback is executed on.- Returns:
- see
subscribe(Mqtt5Subscribe). - See Also:
-
subscribe
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5SubAck> subscribe(@NotNull @NotNull Mqtt5Subscribe subscribe, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback, boolean manualAcknowledgement) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.- Parameters:
subscribe- the Subscribe messages sent to the broker.callback- the callback for consuming the incoming Publish messages matching the subscriptions of the Subscribe message.manualAcknowledgement- whether the Publish messages are acknowledged manually.- Returns:
- see
subscribe(Mqtt5Subscribe). - Since:
- 1.2
- See Also:
-
subscribe
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5SubAck> subscribe(@NotNull @NotNull Mqtt5Subscribe subscribe, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull @NotNull Executor executor, boolean manualAcknowledgement) Subscribes this client with the given Subscribe message and consumes the incoming Publish messages matching the subscriptions of the Subscribe message with a callback.The future is completed and the callback is executed on the given executor.
- Parameters:
subscribe- the Subscribe messages sent to the broker.callback- the callback for consuming the incoming Publish messages matching the subscriptions of the Subscribe message.executor- the executor where the future is completed and the callback is executed on.manualAcknowledgement- whether the Publish messages are acknowledged manually.- Returns:
- see
subscribe(Mqtt5Subscribe). - Since:
- 1.2
- See Also:
-
subscribeWith
Fluent counterpart ofsubscribe(Mqtt5Subscribe),subscribe(Mqtt5Subscribe, Consumer, boolean)andsubscribe(Mqtt5Subscribe, Consumer, Executor, boolean).Calling
Mqtt5AsyncClient.Mqtt5SubscribeAndCallbackBuilder.Call.send()on the returned builder has the same effect as calling one of the following methods:subscribe(Mqtt5Subscribe)if no callback has been supplied to the buildersubscribe(Mqtt5Subscribe, Consumer)if only a callback has been supplied to the buildersubscribe(Mqtt5Subscribe, Consumer, Executor)if a callback and an executor has been supplied to the builder
- Returns:
- the fluent builder for the Subscribe message.
- See Also:
-
publishes
void publishes(@NotNull @NotNull MqttGlobalPublishFilter filter, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback) Globally consumes all incoming Publish messages matching the given filter.- Parameters:
filter- the filter with which all incoming Publish messages are filtered.callback- the callback for all incoming Publish messages matching the given filter.- See Also:
-
publishes
void publishes(@NotNull @NotNull MqttGlobalPublishFilter filter, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull @NotNull Executor executor) Globally consumes all incoming Publish messages matching the given filter.- Parameters:
filter- the filter with which all incoming Publish messages are filtered.callback- the callback for all incoming Publish messages matching the given filter.executor- the executor where the callback is executed on.- See Also:
-
publishes
void publishes(@NotNull @NotNull MqttGlobalPublishFilter filter, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback, boolean manualAcknowledgement) Globally consumes all incoming Publish messages matching the given filter.- Parameters:
filter- the filter with which all incoming Publish messages are filtered.callback- the callback for all incoming Publish messages matching the given filter.manualAcknowledgement- whether the Publish messages are acknowledged manually.- Since:
- 1.2
- See Also:
-
publishes
void publishes(@NotNull @NotNull MqttGlobalPublishFilter filter, @NotNull @NotNull Consumer<@NotNull Mqtt5Publish> callback, @NotNull @NotNull Executor executor, boolean manualAcknowledgement) Globally consumes all incoming Publish messages matching the given filter.- Parameters:
filter- the filter with which all incoming Publish messages are filtered.callback- the callback for all incoming Publish messages matching the given filter.executor- the executor where the callback is executed on.manualAcknowledgement- whether the Publish messages are acknowledged manually.- Since:
- 1.2
- See Also:
-
unsubscribe
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5UnsubAck> unsubscribe(@NotNull @NotNull Mqtt5Unsubscribe unsubscribe) Unsubscribes this client with the given Unsubscribe message.- Parameters:
unsubscribe- the Unsubscribe message sent to the broker.- Returns:
- a
CompletableFuturewhich- completes normally with the UnsubAck message if all Topic Filters of the Unsubscribe message were successfully unsubscribed (the UnsubAck message contains no Error Codes),
- completes exceptionally with a
Mqtt5UnsubAckExceptionwrapping the UnsubAck message if it contains at least one Error Code or - completes exceptionally with a different exception if an error occurred before the Unsubscribe message was sent or before a UnsubAck message was received.
-
unsubscribeWith
@CheckReturnValue @NotNull Mqtt5UnsubscribeBuilder.Send.Start<CompletableFuture<Mqtt5UnsubAck>> unsubscribeWith()Fluent counterpart ofunsubscribe(Mqtt5Unsubscribe).Calling
Mqtt5UnsubscribeBuilder.Send.Complete.send()on the returned builder has the same effect as callingunsubscribe(Mqtt5Unsubscribe)with the result ofMqtt5UnsubscribeBuilder.Complete.build().- Returns:
- the fluent builder for the Unsubscribe message.
- See Also:
-
publish
@NotNull @NotNull CompletableFuture<@NotNull Mqtt5PublishResult> publish(@NotNull @NotNull Mqtt5Publish publish) Publishes the given Publish message.- Parameters:
publish- the Publish message sent to the broker.- Returns:
- a
CompletableFuturewhich- completes normally with the
Mqtt5PublishResultif the Publish message was successfully published (no acknowledgement message contains an Error Code,Mqtt5PublishResult.getError()will always be absent), - completes exceptionally with a
Mqtt5PubAckExceptionorMqtt5PubRecExceptionwrapping the acknowledgement message if it contains an Error Code or - completes exceptionally with a different exception if an error occurred before the Publish message was sent or before an acknowledgement message was received.
- completes normally with the
-
publishWith
@CheckReturnValue @NotNull Mqtt5PublishBuilder.Send<CompletableFuture<Mqtt5PublishResult>> publishWith()Fluent counterpart ofpublish(Mqtt5Publish).Calling
Mqtt5PublishBuilder.Send.Complete.send()on the returned builder has the same effect as callingpublish(Mqtt5Publish)with the result ofMqtt5PublishBuilder.Complete.build().- Returns:
- the fluent builder for the Unsubscribe message.
- See Also:
-
reauth
Re-authenticates this client.- Returns:
- a
CompletableFuturewhich- completes normally when the client was successfully re-authenticated,
- errors with a
Mqtt5AuthExceptionwrapping the Auth message with the Error Code if not re-authenticated successfully or - errors with a different exception if an error occurred before the first Auth message was sent or before the last Auth message was received.
-
disconnect
Disconnects this client with the default Disconnect message.- Returns:
- see
disconnect(Mqtt5Disconnect). - See Also:
-
disconnect
Disconnects this client with the given Disconnect message.- Parameters:
disconnect- the Disconnect message sent to the broker.- Returns:
- the
CompletableFuturewhich- completes when the client was successfully disconnected or
- errors if not disconnected gracefully.
-
disconnectWith
Fluent counterpart ofdisconnect(Mqtt5Disconnect).Calling
Mqtt5DisconnectBuilder.Send.send()on the returned builder has the same effect as callingdisconnect(Mqtt5Disconnect)with the result ofMqtt5DisconnectBuilder.build().- Returns:
- the fluent builder for the Unsubscribe message.
- See Also:
-
toAsync
Description copied from interface:Mqtt5ClientTurns the API of this client into a asynchronous API based on futures and callbacks.The asynchronous API can be used simultaneously with the other APIs.
- Specified by:
toAsyncin interfaceMqtt5Client- Returns:
- a asynchronous API for this client.
-