I have several microservices communicating each other with OpenFeign
. Each one is a submodule of a project(call it "parent"), with its own docker container.
OK. So, when I want to build a client with feign.builder().target()
method, an error occurs claiming that "target values must be absolute". I checked the source code, and it means (feign.RequestTemplate.target(RequestTemplate.java:447)
):
public static boolean isAbsolute(String uri) {
return uri != null && !uri.isEmpty() && uri.startsWith("http");
}
Here comes the question: the url of other services are like:
another-service:8080/check
In local tests, this is not a problem, because the profile local
has http://localhost:8080
and so on. But in an end-to-end test this cannot bypass the absolute check.
So, what to do now?
I just added http://
before the service name and this is fixed.
Looks like when creating containers needing to communicate with each other, docker does two things:
172.26.0.2
, not as localhost
or 192.168.xx.xx
.docker-compose.yml
. Like, in docker-compose.yml
I have service-A
, in the network of docker, I can docker exec -it bash
to run shell and curl http://service-A:8080
to visit it.Note that I used inner ports, not "outer" ports. For example, if service-A has ports config like:
ports:
- "8083:8080"
Inside the network(curl
from other containers) we use 8080, but from "outside"(from host, using Postman) we use 8083.
PS:
I used uname -a
to check the dist of container is Debian and then I apt update && apt install curl
to install curl
executable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With