Closed henryfung3a27 closed 1 year ago
Extra context: these services are defined in the same docker-compose.yml
and they are in the same subnet. They can ping each other with ping <container_name>
.
After a bit more tweak, I found that using IP address instead of the container name in the address
property works.
$ docker inspect my-network
gives the IP addresses.
grpc.client.user-service.address=dns:///172.20.0.5:5000 // <----
grpc.client.user-service.enable-keep-alive=true
grpc.client.user-service.keep-alive-without-calls=true
grpc.client.user-service.negotiation-type=plaintext
However, shouldn't it resolve the name itself? I used the same manner to connect to databases which are running on docker as well and they worked well.
spring.data.mongodb.host=mongodb
spring.data.mongodb.port=27017
I think setting the grpc address with the IP address is not ideal because they change. Is there any solution to hep resolving the name to their IP address?
When I set
grpc.client.user-service.address=static://userservice:5000
I get
Caused by: java.lang.IllegalArgumentException: hostname can't be null
at java.base/java.net.InetSocketAddress.checkHost(InetSocketAddress.java:158) ~[na:na]
at java.base/java.net.InetSocketAddress.<init>(InetSocketAddress.java:225) ~[na:na]
at net.devh.boot.grpc.client.nameresolver.StaticNameResolverProvider.of(StaticNameResolverProvider.java:76) ~[grpc-client-spring-boot-autoconfigure-2.14.0.RELEASE.jar!/:2.14.0.RELEASE]
at net.devh.boot.grpc.client.nameresolver.StaticNameResolverProvider.newNameResolver(StaticNameResolverProvider.java:53) ~[grpc-client-spring-boot-autoconfigure-2.14.0.RELEASE.jar!/:2.14.0.RELEASE]
at io.grpc.NameResolverRegistry$NameResolverFactory.newNameResolver(NameResolverRegistry.java:168) ~[grpc-api-1.51.0.jar!/:1.51.0]
at io.grpc.internal.ManagedChannelImpl.getNameResolver(ManagedChannelImpl.java:749) ~[grpc-core-1.51.0.jar!/:1.51.0]
at io.grpc.internal.ManagedChannelImpl.getNameResolver(ManagedChannelImpl.java:781) ~[grpc-core-1.51.0.jar!/:1.51.0]
at io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:661) ~[grpc-core-1.51.0.jar!/:1.51.0]
at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:631) ~[grpc-core-1.51.0.jar!/:1.51.0]
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:297) ~[grpc-core-1.51.0.jar!/:1.51.0]
at net.devh.boot.grpc.client.channelfactory.AbstractChannelFactory.newManagedChannel(AbstractChannelFactory.java:140) ~[grpc-client-spring-boot-autoconfigure-2.14.0.RELEASE.jar!/:2.14.0.RELEASE]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
at net.devh.boot.grpc.client.channelfactory.AbstractChannelFactory.createChannel(AbstractChannelFactory.java:108) ~[grpc-client-spring-boot-autoconfigure-2.14.0.RELEASE.jar!/:2.14.0.RELEASE]
at net.devh.boot.grpc.client.channelfactory.InProcessOrAlternativeChannelFactory.createChannel(InProcessOrAlternativeChannelFactory.java:86) ~[grpc-client-spring-boot-autoconfigure-2.14.0.RELEASE.jar!/:2.14.0.RELEASE]
at net.devh.boot.grpc.client.inject.GrpcClientBeanPostProcessor.processInjectionPoint(GrpcClientBeanPostProcessor.java:213) ~[grpc-client-spring-boot-autoconfigure-2.14.0.RELEASE.jar!/:2.14.0.RELEASE]
... 42 common frames omitted
That is strange. userservice:5000
looks totally fine to me.
Please debug passing the actual service address to
(e.g. in a unit-test) and check whether and why host
would be null. I'm unable to reproduce it in my setup.
As for the dns resolver not working: Please ask that over at grpc-java and link it here, so I know what went wrong there for the future.
Hmmm, very interesting outcome I have found.
At line 71
final URI uri = URI.create("//" + host);
Where host
is the plain text of the input.
host | uri.getHost() | uri.getPort() |
---|---|---|
userservice:5000 | userservice | 5000 |
user-service:5000 | user-service | 5000 |
user_service:5000 | null |
-1 |
Looks like underscore _
is not allowed in the URI string. It cannot be parsed and thus the host and port are null
.
The reason my example used userservice
is because the original name is something else related to my company work and I chose not to disclose it. (facepalm) What a mistake.
Seems like underscore is acceptable according to rfc3986 (January 2005). But not in Java(?)
2.3. Unreserved Characters
Characters that are allowed in a URI but do not have a reserved
purpose are called unreserved. These include uppercase and lowercase
letters, decimal digits, hyphen, period, underscore, and tilde.
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
In this case, I think there is no issue relating to this repo. I am closing this issue. Thanks a lot.
I created a PR to document this limitation in the docs: #911
The context
I have a python gRPC server service running on docker. I can call the methods from the host with a python client. Now I want to have another SprintBoot client service to call the methods. Both the Python server and SpringBoot client run on docker.
I have the following
application.properties
:And the following Service:
The question
I get the following error on startup.
The application's environment
Which versions do you use?
Additional information
I have read https://github.com/yidongnan/grpc-spring-boot-starter/pull/775#issuecomment-1329023335 to set the properties.
I have read https://github.com/grpc/grpc/blob/master/doc/naming.md as well and I have been tweaking the address property and tried below
But they all give different errors.