Robust iterators for gRPC server-side streams in Java

One useful feature of gRPC is server-side streaming. A client can use this to stream over large amounts of data from a server, for example the result of a large database query. The “blocking” API for this has a familiar Iterator API: Iterator<StreamResponse> iterator = blockingStub.makeStreamingCall(); while (iterator.hasNext()) { StreamResponse response = iterator.next(); // do stuff } However, there are a few hidden issues to think about here: What happens if we get a network error halfway through the stream?...

April 18, 2023 · 4 min · Gautam Raj