Java 11's HTTP/2 API supports reactive streams for handling request and response bodies, enabling memory-efficient streaming without loading entire payloads. The post covers the Flow API's Publisher/Subscriber/Subscription model, how to stream large request bodies using BodyPublisher (keeping only 16KB in memory at a time), and how to reactively process response bodies line-by-line using BodyHandlers.fromLineSubscriber. It also demonstrates using CompletableFuture to expose results, properly handling all error cases including pre-streaming failures, and canceling subscriptions early once a search term is found—cutting runtime to ~45% of blocking calls.
Table of contents
▚ Reactive Stream Crash Course▚ Streaming The Request Body▚ Streaming The Response Body▚ Canceling The Stream▚ ReflectionSort: