public class MqttClientConnection extends CrtResource
CrtResource.ResourceInstance
Constructor and Description |
---|
MqttClientConnection(MqttConnectionConfig config)
Constructs a new MqttClientConnection.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
canReleaseReferencesImmediately()
Determines whether a resource releases its dependencies at the same time the
native handle is released or if it waits.
|
CompletableFuture<Boolean> |
connect()
Connect to the service endpoint and start a session
|
CompletableFuture<Void> |
disconnect()
Disconnects the current session
|
void |
onMessage(java.util.function.Consumer<MqttMessage> handler)
Sets a handler to be invoked whenever a message arrives, subscription or not
|
CompletableFuture<Integer> |
publish(MqttMessage message)
Publishes a message to a topic.
|
CompletableFuture<Integer> |
publish(MqttMessage message,
QualityOfService qos,
boolean retain)
Deprecated.
|
protected void |
releaseNativeHandle()
Frees native resources associated with this connection.
|
CompletableFuture<Integer> |
subscribe(String topic,
QualityOfService qos)
Subscribes to a topic without a handler (messages will only be delivered to
the OnMessage handler)
|
CompletableFuture<Integer> |
subscribe(String topic,
QualityOfService qos,
java.util.function.Consumer<MqttMessage> handler)
Subscribes to a topic
|
CompletableFuture<Integer> |
unsubscribe(String topic)
Unsubscribes from a topic
|
acquireNativeHandle, addRef, addReferenceTo, close, collectNativeResource, collectNativeResources, decRef, getNativeHandle, getResourceLogDescription, isNull, logNativeResources, releaseReferences, removeReferenceTo, setDescription, swapReferenceTo, waitForNoResources
public MqttClientConnection(MqttConnectionConfig config) throws MqttException
config
- Configuration to useMqttException
- If mqttClient is nullprotected void releaseNativeHandle()
releaseNativeHandle
in class CrtResource
protected boolean canReleaseReferencesImmediately()
canReleaseReferencesImmediately
in class CrtResource
public CompletableFuture<Boolean> connect() throws MqttException
MqttException
- If the port is out of rangepublic CompletableFuture<Void> disconnect()
public CompletableFuture<Integer> subscribe(String topic, QualityOfService qos, java.util.function.Consumer<MqttMessage> handler)
topic
- The topic to subscribe toqos
- QualityOfService
for this subscriptionhandler
- A handler which can receive an MqttMessage when a message is
published to the topicpublic CompletableFuture<Integer> subscribe(String topic, QualityOfService qos)
topic
- The topic to subscribe toqos
- QualityOfService
for this subscriptionpublic void onMessage(java.util.function.Consumer<MqttMessage> handler)
handler
- A handler which can receive any MqttMessagepublic CompletableFuture<Integer> unsubscribe(String topic)
topic
- The topic to unsubscribe frompublic CompletableFuture<Integer> publish(MqttMessage message)
message
- The message to publish.@Deprecated public CompletableFuture<Integer> publish(MqttMessage message, QualityOfService qos, boolean retain)
Copyright © 2021. All rights reserved.