How to access the managed channels?
Hello, I am trying to access the managed channels in order to warm up the DNS resolver.
I mean I want the channel to resolve the service host after the application is started. But I couldn't access the managed channels in any way!
So is there a way to do so? or is there any workaround?
Many thanks
Currently, there is no way to access the ManagaedChannels directly. It is planned though.
Why do you wish to warmup the dns resolvers?
One way to do that (per channel) is to send a request to the channel. E.g. a health request.
That is a good idea. But the problem is that the service doesn't have health check methods! (Unless there is another way 🙈 ) And the actual endpoints require some user context that I don't want to access during the service startup.
You dont have to use an existing method/valid input. Just create the stub call it and discard the result (error). Like normal http you can call any url and the browser will resolve the hostname/show an error. That way, the dns is initialized.
The problem is that we have many interceptors that check some data and I don't want to bypass those, so if I provide the wrong data, the call will not happen, that is why it is not an option for me.
And regarding your statement:
Currently, there is no way to access the ManagaedChannels directly. It is planned though
Can I help somehow with that implementation? I can dedicate time to that.
There are two parts that I would like to do.
- Extract the injection logic from the bean post processor, so that it can be injected itself
- The injector is also responsible to apply the interceptors, removing this task from the channel factory
- If possible, it should also split the injection step from channel factory (using a lazy forwarding channel; that way there is no longer a dependency between the InProcessChannel and Server)
- Replace the different ManagedChannel/ServerFactories with something that are just use grpc native builder factory + configurer to build the instance, all configuration logic should be moved from the factories to configurers
From an architectural perspective it should look somewhat like this:
Which part do you wish to tackle?
- Split GrpcClientBeanPostProcessor into GrpcClientInjector
- Rewrite ManagedChannelFactory
I would start with the first one Split GrpcClientBeanPostProcessor into GrpcClientInjector
Awesome. The public API of the injector should be somewhat like this:
<T> T get(String name, Class<T> type)<T> T get(@GrpcClient client, Class<T> type)
Where T is the type of the field and @GrpcClient the annotation on that field.
The name variant is a simplification for manual use where you dont want to set any additional options.
Feel free to adjust the method signature to your liking/implementation needs.
My case is integration test. I need to inspect some behaviour and signup to ManagedChannel.notifyWhenStateChanged. I very need this feature.
