grpc-spring icon indicating copy to clipboard operation
grpc-spring copied to clipboard

Does GRPCClient reuses the channel? Need to understand underlying work behaviour of gRPCClient annotation

Open banandh opened this issue 1 year ago • 1 comments

About gRPC Channel

gRPC channel -A gRPC channel provides a connection to a gRPC server on a specified host and port.

Does @GrpcClient creates new channel everytime or it reuses the channel to make request?

Do we have option for below customization in java grpccpringboot library??

From https://learn.microsoft.com/en-us/aspnet/core/grpc/performance?view=aspnetcore-7.0

Channels are safe to share and reuse between gRPC calls:

gRPC clients are created with channels. gRPC clients are lightweight objects and don't need to be cached or reused. Multiple gRPC clients can be created from a channel, including different types of clients. A channel and clients created from the channel can safely be used by multiple threads. Clients created from the channel can make multiple simultaneous calls.

banandh avatar Apr 29 '23 10:04 banandh

Stubs/Channels aren't cached on a framework level. They are implicitly cached by the beans having a reference to them. ManagedChannels are explicitly cached, because they carry an actual connection that takes time to establish.

https://github.com/yidongnan/grpc-spring-boot-starter/blob/80e12c63f9c38e81f171cc51d2ef259124007c68/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/channelfactory/AbstractChannelFactory.java#L75

Does that answer your question?

ST-DDT avatar Apr 29 '23 10:04 ST-DDT