grpc-ecosystem / grpc-spring

Spring Boot starter module for gRPC framework.
https://grpc-ecosystem.github.io/grpc-spring/
Apache License 2.0
3.48k stars 816 forks source link

如何去动态创建channel #848

Closed saiyujs closed 1 year ago

saiyujs commented 1 year ago

我有多个服务端,其中有10个服务端在机房A,服务名叫xxxx-A;有另外10个服务端在机房B,服务名叫xxx-B。 需求有的请求必须要请求服务xxx-A,有的请求必须要请求服务xxx-B。 以后可能还会有机房C,所以如何可以动态创建channel? 其功能就是类似rest+@LoadBalanced,可以通过我传入的服务名,动态选择channel。 感谢回复!!

ST-DDT commented 1 year ago

English


Currently, there is no easy way to do that. One way is creating the Channel via the GrpcChannelFactory and create the Stub yourself in the calling code (potentially cached). We plan to make the stubs directly accessible/requestable as described here: https://github.com/yidongnan/grpc-spring-boot-starter/issues/741#issuecomment-1247148603

Closing as duplicate.

saiyujs commented 1 year ago

image image 分享一下解决方法。 通过https://github.com/yidongnan/grpc-spring-boot-starter/issues/741#issuecomment-1247148603 里面的架构图,得到启发,thx!!!