fix cause deadlock while use subscribeAsync demo in java client doc.
@@ -306,16 +306,14 @@ Pattern allTopicsInNamespace = Pattern.compile("persistent://public/default.*");
consumerBuilder
.topics(topics)
.subscribeAsync()
- .thenAccept(consumer -> {
- do {
- try {
- Message msg = consumer.receive();
+ .thenAccept(this::receiveMessageFromConsumer);
+
+private void receiveMessageFromConsumer(Consumer consumer) {
+ consumer.receiveAsync().thenAccept(message -> {
// Do something with the received message
- } catch (PulsarClientException e) {
- e.printStackTrace();
- }
- } while (true);
+ receiveMessageFromConsumer(consumer);
});
+}
```
### Subscription modes
