2 分钟阅读
https://grpc.io/docs/guides/wait-for-ready/
Explains how to configure RPCs to wait for the server to be ready before sending the request.
解释了如何配置 RPC,在发送请求之前等待服务器就绪。
This is a feature which can be used on a stub which will cause the RPCs to wait for the server to become available before sending the request. This allows for robust batch workflows since transient server problems won’t cause failures. The deadline still applies, so the wait will be interrupted if the deadline is passed.
这是一个可以用于存根(stub)的特性,它会导致 RPC 在发送请求之前等待服务器可用。这样可以实现稳健的批处理工作流,因为临时的服务器问题不会导致失败。仍然适用截止时间(deadline),所以如果超过截止时间,等待将被中断。
When an RPC is created when the channel has failed to connect to the server, without Wait-for-Ready it will immediately return a failure; with Wait-for-Ready it will simply be queued until the connection becomes ready. The default is without Wait-for-Ready.
当通道无法连接到服务器时创建 RPC,如果没有设置等待就绪(Wait-for-Ready),它会立即返回失败;如果设置了等待就绪,它将被简单地排队,直到连接就绪。默认情况下是不使用等待就绪。
For detailed semantics see this.
有关详细的语义,请参阅这个文档。
You can specify for a stub whether or not it should use Wait-for-Ready, which will automatically be passed along when an RPC is created.
您可以为存根指定是否应该使用等待就绪,当创建 RPC 时,它会自动传递。
The RPC can still fail for other reasons besides the server not being ready, so error handling is still necessary.
除了服务器未就绪之外,RPC 仍然可能因其他原因而失败,因此仍然需要进行错误处理。
The following shows the sequence of events that occur, when a client sends a message to a server, based upon channel state and whether or not Wait-for-Ready is set.
以下是基于通道状态和是否设置了等待就绪的客户端向服务器发送消息时发生的事件序列。
The following is a state based view
以下是基于状态的视图
onReady
Handler (for languages that support this).onReady
处理程序(适用于支持此功能的语言)结合使用以提高效率。语言 | 示例 |
---|---|
Java | Java 示例 |
Go | Go 示例 |
Python | Python 示例 |