我想使客户端流式传输阻塞。该协议(protocol)的定义如下所示:
rpc RecordRoute(stream Point) returns (RouteSummary) {}
正如文档中所说,对于某些类型的流式调用,只能使用异步 stub :
a non-blocking/asynchronous stub that makes non-blocking calls to the server, where the response is returned asynchronously. You can make certain types of streaming call only using the asynchronous stub.
那么我怎样才能使调用阻塞/同步呢?是否可以?
最佳答案
阻塞 stub 只能用于客户端仅发送单个请求的 RPC。对于客户端流式调用,您只能使用异步 stub 。生成的阻塞 stub 代码不包含客户端流式传输或双向流式传输方法的 RPC 方法。
如果你想避免由于异步请求造成的过度缓冲,你可以使用 CallStreamObServer
API 做手动流量控制。使用一些外部同步,例如 CountDownLatch
,异步 API 可以同步运行。看看如何gRPC's manual flow control example作品。
关于java - 在 gRPC Java 应用程序中使客户端流同步/阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62880770/