-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provides auto registration of gRPC client beans #91
Comments
I like the idea of a base package. It would be better represented in an annotation IMO (like We are still waiting on some actual users to ask for this feature (other than existing library authors that is). |
@dsyer We are currently using grpc-ecosystem/grpc-spring and are interested in switching to official integration. The functionality @DanielLiu1123 is referring to would be helpful for us, as we have many different clients and services. |
Thanks for that. Anyone else who has an opinion, please do add it. Can we dig into your scenario a bit? How many clients are we talking about? How many stubs and how many channels? I would be surprised (and a little horrified) if you had really a lot of different channels. So is it the creation of multiple stubs for the same channel that we need to focus on? The existing ecosystem projects each solve this in different ways and none of them is a great solution IMO, so we need to collect more data on what the actual requirement is. |
Yes, primarily the creation of multiple stubs for the same channel. We have api gateway that communicates with all our services via gRPC, currently it's 6 channels and about 60 stubs. |
Creation of a stub is trivial, right? So are you saying you'd rather have 200 or 300 beans automatically created for you and only use 60 of them, than declare which ones you need explicitly, even though that is very straightforward (and has its own native API in |
I think For most users, using @EnableGrpcClients(basePackages = {
"io.grpc",
"com.example"
}) For experienced developers or performance-critical (startup time) applications, we can enumerate the specific classes that require bean creation. This approach avoids classpath scanning and prevents extra beans from being registered. @EnableGrpcClients(clients = {
SimpleServiceGrpc.SimpleServiceBlockingStub.class,
SimpleServiceGrpc.SimpleServiceStub.class
}) |
That might get us closer. I'm not sure I like that the base packages version creates all the blocking and non-blocking (and reactive?) stubs still. Also we need a way to map a client id/name to a group of stubs. We see this pattern already in the ecosystem, and also in Spring Cloud OpenFeign. The HTTP Interface support in Spring Framework is also evolving in that direction, with a named "client group" being the key to configuring different concerns like interceptors and base URLs (like a named Feign client in Spring Cloud, and a lot like the Maybe something like this would work (allow multiple enumerations keyed to the channel name): @EnableGrpcClients(clients = {
...
SimpleServiceGrpc.SimpleServiceStub.class
})
@EnableGrpcClients(name = "basic", clients = {
...
OtherServiceGrpc.OtherServiceBlockingStub.class
}) (The default name is the default channel.) The base package problem is harder. I'd also like to be able to specify a class not a string (like we already support for component scans and Spring Dtaa repositories). IDK, maybe @EnableGrpcClients(basePackageClasses = SimpleServiceGrpc.class, factory = GrpcStubClients.class) The factory is located from the application context (there has to be a bean of that type). The default could be With the factory idea I guess the other example could be written as @EnableGrpcClients(factory = GrpcStubClients.class, clients = {
...
SimpleServiceGrpc.class
})
@EnableGrpcClients(name = "basic", factory = GrpcBlockingStubClients.class, clients = {
...
OtherServiceGrpc.class
}) I'm not sure it really all fits in one annotation at this point. We can watch what happens in Spring Boot for HTTP interface clients. Maybe it would help to implement the factories and see where that takes us. I guess there's no way to avoid reflection there, but it's the least evil way to do things. |
As mentioned in this comment, users still need to manually register client beans:
In real-world applications, a service might use dozens or even hundreds of gRPC clients (I’m working on such a project). Manually registering gRPC client beans is unsatisfactory, especially when considering migrating starters from other community implementations to
spring-grpc
.Similar issues occur with HTTP interfaces. We can look at this issue and how they plan to solve it. The same pattern should work for gRPC clients.
Here is a feasible solution I propose, grpc-starter provides a fully configuration-driven approach:
Then you can inject gRPC client beans into any Spring beans. I hope
spring-grpc
can provide a similar solution.The text was updated successfully, but these errors were encountered: