Skip to content

Commit 581e34f

Browse files
committed
pr changes
1 parent e7ba4f2 commit 581e34f

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

documents/MQTT5_Userguide.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
+ [Client Operations](#client-operations)
2424
+ [Publish](#publish)
2525
+ [Subscribe and Unsubscribe](#subscribe-and-unsubscribe)
26+
+ [Advanced Operations and Settings](#advanced-operations-and-settings)
27+
* [Manual Publish Acknowledgement](#manual-publish-acknowledgement)
2628
+ [MQTT5 Best Practices](#mqtt5-best-practices)
27-
* [Advanced Operations and Settings](#advanced-operations-and-settings)
28-
+ [Manual Publish Acknowledgement](#manual-publish-acknowledgement)
2929

3030
# Introduction
3131

@@ -556,17 +556,6 @@ unsubBuilder.withSubscription("hello/world/qos1");
556556
client.unsubscribe(unsubBuilder.build()).get(60, TimeUnit.SECONDS);
557557
~~~
558558
559-
## MQTT5 Best Practices
560-
561-
Below are some best practices for the MQTT5 client that are recommended to follow for the best development experience:
562-
563-
* When creating MQTT5 clients, make sure to use ClientIDs that are unique! If you connect two MQTT5 clients with the same ClientID, they will Disconnect each other! If you do not configure a ClientID, the MQTT5 server will automatically assign one.
564-
* Use the minimum QoS you can get away with for the lowest latency and bandwidth costs. For example, if you are sending data consistently multiple times per second and do not have to have a guarantee the server got each and every publish, using QoS 0 may be ideal compared to QoS 1. Of course, this heavily depends on your use case but generally it is recommended to use the lowest QoS possible.
565-
* If you are getting unexpected disconnects when trying to connect to AWS IoT Core, make sure to check your IoT Core Thing’s policy and permissions to make sure your device is has the permissions it needs to connect!
566-
* Make sure to always call `close()` when finished a MQTT5 client to avoid native resource leaks!
567-
* For [publish](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#publish(software.amazon.awssdk.crt.mqtt5.packets.PublishPacket)), [subscribe](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#subscribe(software.amazon.awssdk.crt.mqtt5.packets.SubscribePacket)), and [unsubscribe](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#unsubscribe(software.amazon.awssdk.crt.mqtt5.packets.UnsubscribePacket)), make sure to check the reason codes in the ACK ([PubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/PubAckPacket.html), [SubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/SubAckPacket.html), and [UnsubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/UnsubAckPacket.html) respectively) to see if the operation actually succeeded.
568-
* You MUST NOT perform blocking operations on any callback, or you will cause a deadlock. For example: in the `onMessageReceived` callback, do not send a publish, and then wait for the future to complete within the callback. The Client cannot do work until your callback returns, so the thread will be stuck.
569-
570559
## Advanced Operations and Settings
571560
572561
### Manual Publish Acknowledgement
@@ -576,7 +565,7 @@ By default, the MQTT5 client automatically sends a PUBACK for every QoS 1 PUBLIS
576565
To take manual control of the PUBACK, call `publishReturn.acquirePublishAcknowledgementControl()` **within** the `onMessageReceived` callback. This returns a `Mqtt5PublishAcknowledgementControlHandle` that you can store and use later to send the PUBACK by calling `client.invokePublishAcknowledgement()`.
577566
578567
**Important constraints:**
579-
* `acquirePublishAcknowledgementControl()` must be called within the `onMessageReceived` callback. Calling it outside the callback or after it returns will return `null`.
568+
* `acquirePublishAcknowledgementControl()` must be called within the `onMessageReceived` callback. Calling it outside the callback after it returns or from a different thread will return `null`.
580569
* `acquirePublishAcknowledgementControl()` may only be called once per received PUBLISH. Subsequent calls will return `null`.
581570
* This is only relevant for QoS 1 messages. Calling it on a QoS 0 message will return `null`.
582571
* If `acquirePublishAcknowledgementControl()` is not called, the client will automatically send the PUBACK when the callback returns.
@@ -617,3 +606,22 @@ if (handle != null) {
617606
client.invokePublishAcknowledgement(handle);
618607
}
619608
~~~
609+
610+
**AWS IoT broker redelivery behavior**
611+
612+
The AWS IoT broker will periodically resend unacknowledged QoS 1 PUBLISH packets. These redeliveries should be treated as duplicates even if the DUP flag in the PUBLISH packet is not set. If `acquirePublishAcknowledgementControl()` is not called again for a redelivered packet, the acknowledgement will be sent automatically.
613+
614+
**Session resumption after disconnect/reconnect**
615+
616+
Upon a disconnect and reconnect of the MQTT5 client, if a session is resumed, any previously acquired `Mqtt5PublishAcknowledgementControlHandle` is void. The broker will resend the unacknowledged PUBLISH packet, and `acquirePublishAcknowledgementControl()` must be called again within the callback for that resent packet. If the resent packet is not handled for manual acknowledgement, the acknowledgement will be sent automatically.
617+
618+
## MQTT5 Best Practices
619+
620+
Below are some best practices for the MQTT5 client that are recommended to follow for the best development experience:
621+
622+
* When creating MQTT5 clients, make sure to use ClientIDs that are unique! If you connect two MQTT5 clients with the same ClientID, they will Disconnect each other! If you do not configure a ClientID, the MQTT5 server will automatically assign one.
623+
* Use the minimum QoS you can get away with for the lowest latency and bandwidth costs. For example, if you are sending data consistently multiple times per second and do not have to have a guarantee the server got each and every publish, using QoS 0 may be ideal compared to QoS 1. Of course, this heavily depends on your use case but generally it is recommended to use the lowest QoS possible.
624+
* If you are getting unexpected disconnects when trying to connect to AWS IoT Core, make sure to check your IoT Core Thing's policy and permissions to make sure your device is has the permissions it needs to connect!
625+
* Make sure to always call `close()` when finished a MQTT5 client to avoid native resource leaks!
626+
* For [publish](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#publish(software.amazon.awssdk.crt.mqtt5.packets.PublishPacket)), [subscribe](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#subscribe(software.amazon.awssdk.crt.mqtt5.packets.SubscribePacket)), and [unsubscribe](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#unsubscribe(software.amazon.awssdk.crt.mqtt5.packets.UnsubscribePacket)), make sure to check the reason codes in the ACK ([PubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/PubAckPacket.html), [SubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/SubAckPacket.html), and [UnsubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/UnsubAckPacket.html) respectively) to see if the operation actually succeeded.
627+
* You MUST NOT perform blocking operations on any callback, or you will cause a deadlock. For example: in the `onMessageReceived` callback, do not send a publish, and then wait for the future to complete within the callback. The Client cannot do work until your callback returns, so the thread will be stuck.

0 commit comments

Comments
 (0)