When using gRPC from Java, can I cache stubs (clients) and call them in a multi-threaded environment or are the channels thread-safe and can be safely cached?
If there is a network outage, should I recreate the channel or it is smart enough to reconnect? I couldn't find relevant info on http://www.grpc.io/docs/
Thanks
Answer to first question:
Channels are thread safe; io.grpc.Channel
is marked with @ThreadSafe
annotation. Stubs are also thread-safe, which is why reconfiguration creates a new stub.
Answer to second question:
If there is a network outage, you don't need to recreate the channel. The channel will reconnect with exponential backoff, roughly as described by the connection backoff doc. Java does not 100% conform to that algorithm, because it doesn't increase connection timeouts in later retries. (Not to be confused with the exponential backoff, which is implemented.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With