atharvalade commented on code in PR #2711:
URL: https://github.com/apache/iggy/pull/2711#discussion_r2818206544
##########
examples/java/README.md:
##########
@@ -64,6 +64,112 @@ You can also customize the server using environment
variables:
IGGY_HTTP_ENABLED=true IGGY_TCP_ADDRESS=0.0.0.0:8090 cargo run --bin
iggy-server
```
+## Blocking vs. Async - When to Use Each
Review Comment:
Moved the "Blocking vs. Async" section below the examples so the doc flows
from basics to advanced
##########
examples/java/README.md:
##########
@@ -132,18 +238,53 @@ Building streams with advanced configuration:
Shows how to use the stream builder API to create and configure streams with
custom settings.
-## Async Client
+## Key Async Patterns
-The following example demonstrates how to use the asynchronous client:
+### CompletableFuture Chaining
-Async producer example:
-
-```bash
-./gradlew runAsyncProducer
+```java
+client.connect()
+ .thenCompose(v -> client.login())
+ .thenCompose(identity -> client.streams().createStream("my-stream"))
+ .thenAccept(stream -> System.out.println("Created: " + stream.name()))
+ .exceptionally(ex -> {
+ System.err.println("Error: " + ex.getMessage());
+ return null;
+ });
```
-Async consumer example:
+### Pipelining for Throughput
-```bash
-./gradlew runAsyncConsumerExample
+```java
+List<CompletableFuture<Void>> sends = new ArrayList<>();
+for (int i = 0; i < 10; i++) {
+ sends.add(client.messages().sendMessages(...));
+}
+CompletableFuture.allOf(sends.toArray(new CompletableFuture[0])).join();
+```
+
+### Thread Pool Offloading
+
+```java
+// WRONG - blocks Netty event loop
+client.messages().pollMessages(...)
+ .thenAccept(polled -> {
+ saveToDatabase(polled); // blocking I/O!
+ });
+
+// CORRECT - offloads to processing pool
+var processingPool = Executors.newFixedThreadPool(8);
+client.messages().pollMessages(...)
+ .thenAcceptAsync(polled -> {
+ saveToDatabase(polled); // runs on processingPool
+ }, processingPool);
```
+
+## Next Steps
Review Comment:
fair
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]