Package software.amazon.awssdk.crt.mqtt
Class MqttClientConnection
java.lang.Object
software.amazon.awssdk.crt.CrtResource
software.amazon.awssdk.crt.mqtt.MqttClientConnection
- All Implemented Interfaces:
AutoCloseable
This class wraps aws-c-mqtt to provide the basic MQTT pub/sub functionality
via the AWS Common Runtime
MqttClientConnection represents a single connection from one MqttClient to an
MQTT service endpoint
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.awssdk.crt.CrtResource
CrtResource.ResourceInstance -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new MqttClientConnection.MqttClientConnection(Mqtt5Client mqtt5client, MqttClientConnectionEvents callbacks) Constructs a new MqttClientConnection from a Mqtt5Client. -
Method Summary
Modifier and TypeMethodDescriptionconnect()Connect to the service endpoint and start a sessionDisconnects the current sessionReturns statistics about the current state of the MqttClientConnection's queue of operations.voidonMessage(Consumer<MqttMessage> handler) Sets a handler to be invoked whenever a message arrives, subscription or notpublish(MqttMessage message) Publishes a message to a topic.publish(MqttMessage message, QualityOfService qos, boolean retain) Deprecated.subscribe(String topic, QualityOfService qos) Subscribes to a topic without a handler (messages will only be delivered to the OnMessage handler)subscribe(String topic, QualityOfService qos, Consumer<MqttMessage> handler) Subscribes to a topicunsubscribe(String topic) Unsubscribes from a topicMethods inherited from class software.amazon.awssdk.crt.CrtResource
addRef, addReferenceTo, close, collectNativeResource, collectNativeResources, decRef, getNativeHandle, getResourceLogDescription, isNull, logNativeResources, logNativeResources, removeReferenceTo, setDescription, waitForNoResources
-
Constructor Details
-
MqttClientConnection
Constructs a new MqttClientConnection. Connections are reusable after being disconnected.- Parameters:
config- Configuration to use- Throws:
MqttException- If mqttClient is null
-
MqttClientConnection
public MqttClientConnection(Mqtt5Client mqtt5client, MqttClientConnectionEvents callbacks) throws MqttException Constructs a new MqttClientConnection from a Mqtt5Client. Connections are reusable after being disconnected.- Parameters:
mqtt5client- the mqtt5 client to setup fromcallbacks- connection callbacks triggered when receive connection events- Throws:
MqttException- If mqttClient is null
-
-
Method Details
-
connect
Connect to the service endpoint and start a session- Returns:
- Future result is true if resuming a session, false if clean session
- Throws:
MqttException- If the port is out of range
-
disconnect
Disconnects the current session- Returns:
- When this future completes, the disconnection is complete
-
subscribe
public CompletableFuture<Integer> subscribe(String topic, QualityOfService qos, Consumer<MqttMessage> handler) Subscribes to a topic- Parameters:
topic- The topic to subscribe toqos-QualityOfServicefor this subscriptionhandler- A handler which can receive an MqttMessage when a message is published to the topic- Returns:
- Future result is the packet/message id associated with the subscribe operation
-
subscribe
Subscribes to a topic without a handler (messages will only be delivered to the OnMessage handler)- Parameters:
topic- The topic to subscribe toqos-QualityOfServicefor this subscription- Returns:
- Future result is the packet/message id associated with the subscribe operation
-
onMessage
Sets a handler to be invoked whenever a message arrives, subscription or not- Parameters:
handler- A handler which can receive any MqttMessage
-
unsubscribe
Unsubscribes from a topic- Parameters:
topic- The topic to unsubscribe from- Returns:
- Future result is the packet/message id associated with the unsubscribe operation
-
publish
Publishes a message to a topic.- Parameters:
message- The message to publish.- Returns:
- Future value is the packet/message id associated with the publish operation
-
publish
@Deprecated public CompletableFuture<Integer> publish(MqttMessage message, QualityOfService qos, boolean retain) Deprecated. -
getOperationStatistics
Returns statistics about the current state of the MqttClientConnection's queue of operations.- Returns:
- Current state of the connection's queue of operations.
-