Skip to content

Commit

Permalink
Added more comments to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Oct 25, 2019
1 parent 24fda91 commit 3a49f4e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.concurrent.TimeUnit;

/**
* Small completely asynchronous example.
*
* @author Silvio Giebl
*/
public class AsyncDemo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.concurrent.CountDownLatch;

/**
* Shows MQTT 5 features like session expiry, message expiry, user properties, topic aliases, flow control
* Shows MQTT 5 features like session expiry, message expiry, user properties, topic aliases, flow control.
*
* @author Silvio Giebl
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class ReconnectStrategy {

public static void main(final String[] args) throws InterruptedException {
// defaultReconnect();
// customizedReconnect();
completelyCustom();
}
Expand Down Expand Up @@ -103,7 +104,7 @@ private static CompletableFuture<byte[]> getOAuthToken() {
TimeUnit.SECONDS.sleep(1);
System.out.println("OAuth server is slow to respond ...");
}
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
e.printStackTrace();
}
return new byte[] {1, 2, 3};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;

/**
* Shows how to implement a request/response pattern using response topic and correlation data.
*
* @author Silvio Giebl
*/
public class RequestResponse {

public static void main(String[] args) {
public static void main(final String[] args) {
final Mqtt5Client requester = Mqtt5Client.builder().serverHost("broker.hivemq.com").build();
final Mqtt5Client responder = Mqtt5Client.builder().serverHost("broker.hivemq.com").build();

Expand All @@ -38,18 +40,18 @@ public static void main(String[] args) {
.subscribeStreamWith()
.topicFilter("request/topic")
.applySubscribe()
.map(publish -> Mqtt5Publish.builder()
.topic(publish.getResponseTopic().get())
.qos(publish.getQos())
.map(requestPublish -> Mqtt5Publish.builder()
.topic(requestPublish.getResponseTopic().get())
.qos(requestPublish.getQos())
.payload("response".getBytes())
.correlationData(publish.getCorrelationData().orElse(null))
.correlationData(requestPublish.getCorrelationData().orElse(null))
.build()))
.subscribe();
.subscribe(); // this call is a reactive streams subscribe call, not an MQTT subscribe

requester.toAsync()
.subscribeWith()
.topicFilter("response/topic")
.callback(publish -> System.out.println("received response"))
.callback(responsePublish -> System.out.println("received response"))
.send()
.thenCompose(subAck -> requester.toAsync()
.publishWith()
Expand Down

0 comments on commit 3a49f4e

Please sign in to comment.