|
18 | 18 | * [Websocket Connection with Cognito Authentication Method](#websocket-connection-with-cognito-authentication-method) |
19 | 19 | + [Adding an HTTP Proxy](#adding-an-http-proxy) |
20 | 20 | + [How to create a MQTT5 client](#how-to-create-a-mqtt5-client) |
| 21 | + * [Lifecycle Management](#lifecycle-management) |
21 | 22 | + [How to Start and Stop](#how-to-start-and-stop) |
22 | | - + [How to Publish](#how-to-publish) |
23 | | - + [How to Subscribe and Unsubscribe](#how-to-subscribe-and-unsubscribe) |
| 23 | + + [Client Operations](#client-operations) |
| 24 | + + [How to Publish](#how-to-publish) |
| 25 | + + [How to Subscribe and Unsubscribe](#how-to-subscribe-and-unsubscribe) |
24 | 26 | + [MQTT5 Best Practices](#mqtt5-best-practices) |
25 | 27 |
|
26 | 28 | # Introduction |
@@ -351,6 +353,8 @@ SDK Proxy support also includes support for basic authentication and TLS-to-prox |
351 | 353 |
|
352 | 354 | Once a MQTT5 client builder has been created, it is ready to make a [MQTT5 client](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html). Something important to note is that once a MQTT5 client is built and finalized, the resulting MQTT5 client cannot have its settings modified! Further, modifications to the MQTT5 client builder will not change the settings of already created the MQTT5 clients. Before building a MQTT5 client from a MQTT5 client builder, make sure to have everything fully setup. |
353 | 355 |
|
| 356 | +### Lifecycle Management |
| 357 | +
|
354 | 358 | For almost every MQTT5 client, it is extremely important to setup [LifecycleEvents](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5ClientOptions.LifecycleEvents.html) callbacks. [LifecycleEvents](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5ClientOptions.LifecycleEvents.html) are invoked when the MQTT5 client connects, fails to connect, disconnects, and is stopped. Without these callbacks setup, it will be incredibly hard to determine the state of the MQTT5 client. To setup [LifecycleEvents](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5ClientOptions.LifecycleEvents.html) callbacks, see the following code: |
355 | 359 |
|
356 | 360 | ~~~ java |
@@ -482,7 +486,9 @@ client.stop(disconnectBuilder.build()); |
482 | 486 | client.close(); |
483 | 487 | ~~~ |
484 | 488 |
|
485 | | -## How to Publish |
| 489 | +## Client Operations |
| 490 | +
|
| 491 | +### Publish |
486 | 492 |
|
487 | 493 | The [publish](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#publish(software.amazon.awssdk.crt.mqtt5.packets.PublishPacket)) operation takes a description of the PUBLISH packet you wish to send and returns a promise containing a [PublishResult](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/PublishResult.html). The returned [PublishResult](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/PublishResult.html) will contain different data depending on the QoS used in the publish. |
488 | 494 |
|
@@ -518,7 +524,7 @@ PublishResult result = published.get(60, TimeUnit.SECONDS); |
518 | 524 |
|
519 | 525 | Note that publishes made while a MQTT5 client is disconnected and offline will be put into a queue. Once reconnected, the MQTT5 client will send any publishes made while disconnected and offline automatically. |
520 | 526 |
|
521 | | -## How to Subscribe and Unsubscribe |
| 527 | +### Subscribe and Unsubscribe |
522 | 528 |
|
523 | 529 | The [subscribe](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/Mqtt5Client.html#subscribe(software.amazon.awssdk.crt.mqtt5.packets.SubscribePacket)) operation takes a description of the [SubscribePacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/SubscribePacket.html) you wish to send and returns a promise that resolves successfully with the corresponding [SubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/SubAckPacket.html) returned by the broker; the promise is rejected with an error if anything goes wrong before the [SubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/SubAckPacket.html) is received. |
524 | 530 | You should always check the reason codes of a [SubAckPacket](https://awslabs.github.io/aws-crt-java/software/amazon/awssdk/crt/mqtt5/packets/SubAckPacket.html) completion to determine if the subscribe operation actually succeeded. |
|
0 commit comments