Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feign.Builder "target values must be absolute" error: how to call docker container with absolute url?

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?

like image 908
WesternGun Avatar asked Sep 17 '19 13:09

WesternGun


1 Answers

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:

  • creating a network composed by these containers, and assign IP for each. In my case, the IP are like 172.26.0.2, not as localhost or 192.168.xx.xx.
  • acting as a DNS server: it map IP to domains same as service name in 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.

like image 112
WesternGun Avatar answered Nov 18 '22 01:11

WesternGun