What is the role of net.devh.boot.grpc.server.nameresolver.SelfNameResolver
The context
I recently came to study this source code and want to learn the principle, but I found that there is a piece of code that I didn't understand, I hope I can get help.
The question
Using eureka as service discovery, does the server still need a NameResolver? Because I don't understand how NameResolver is registered when service discovery via eureka
The purpose of the SelfNameResolver is connecting to your own application via port.
This is mainly useful for integration tests, but may also be used for other purposes such as internally converting web-requests to grpc-requests.
If you use a service discovery, such as eureka, then you still need a NameResolver because you still have to give a way for grpc to access the service discovery. The service discovery is the server, the name resolver is the client/the converter between the client and the grpc framework.
Getting the target service data from the discovery client:
https://github.com/yidongnan/grpc-spring-boot-starter/blob/7c6cccbf25552717fdc3a19a3b70193dc91494d9/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver/DiscoveryClientNameResolver.java#L157-L159
Converting the discovery client data format to grpc format:
https://github.com/yidongnan/grpc-spring-boot-starter/blob/7c6cccbf25552717fdc3a19a3b70193dc91494d9/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver/DiscoveryClientNameResolver.java#L327-L333
Does this answer your question?
Thank you very much for your answer, I probably understand the role of SelfNameResolver, I still need to learn more