dockermicroservicesamazon-elastic-beanstalknetflix-eurekadockerrun.aws.json

Eureka-client not able to call another Eureka-client, throws UnknownHostException


I have 3 components - Eureka Server, Currency Exchange Service, and Currency Conversion Service. I have dockerized all 3 microservices. When I run these containers using docker engine(docker-compose.yml) its working fine. But when I deploy these services into AWS Beanstalk the problem occurs. I can see services are able to register to Eureka Server. I can call the Currency Exchange service and able to retrieve values. But when I call Currency Conversion service which has a dependency on Currency Exchange service the communication fails. Currency Conversion Service able to retrieve data for calling the Currency Exchange service from Eureka Server but when it calls the Currency Exchange service it gets unknown host exception. Can someone please help? Following is my Dockerrun.aws.json details -

{
  "AWSEBDockerrunVersion": 2,
  "volumes": [
    {
      "name": "eureka-server",
      "host": {
        "sourcePath": "/var/app/current/eureka-server"
      }
    },
    {
      "name": "currency-exchange-service",
      "host": {
        "sourcePath": "/var/app/current/currency-exchange-service"
      }
    },
    {
      "name": "currency-conversion-service",
      "host": {
        "sourcePath": "/var/app/current/currency-conversion-service"
      }
    },
    {
      "name": "nginx-proxy-conf",
      "host": {
        "sourcePath": "/var/app/current/proxy/conf.d"
      }
    }
  ],
  "containerDefinitions": [
    {
      "name": "eureka-server",
      "image": "<name>/<tag_of_service>",
      "essential": true,
      "memoryReservation": 128,
      "mountPoints": [
        {
          "sourceVolume": "eureka-server",
          "containerPath": "/var/app"
        }
      ],
      "portMappings": [
        {
          "hostPort": 8761,
          "containerPort": 8761
        }
      ]
    },
    {
      "name": "currency-exchange-service",
      "image": "<name>/<tag_of_service>",
      "essential": true,
      "memoryReservation": 128,
      "mountPoints": [
        {
          "sourceVolume": "currency-exchange-service",
          "containerPath": "/var/app"
        }
      ],
      "portMappings": [
        {
          "hostPort": 8000,
          "containerPort": 8000
        }
      ],
      "links": [
        "eureka-server"
      ]
    },
    {
      "name": "currency-conversion-service",
      "image": "<name>/<tag_of_service>",
      "essential": true,
      "memoryReservation": 128,
      "mountPoints": [
        {
          "sourceVolume": "currency-conversion-service",
          "containerPath": "/var/app"
        }
      ],
      "portMappings": [
        {
          "hostPort": 8100,
          "containerPort": 8100
        }
      ],
      "links": [
        "eureka-server"
      ]
    },
    {
      "name": "nginx-proxy",
      "image": "nginx",
      "essential": true,
      "memoryReservation": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ],
      "links": [
        "eureka-server", "currency-exchange-service", "currency-conversion-service"
      ],
      "mountPoints": [
        {
          "sourceVolume": "nginx-proxy-conf",
          "containerPath": "/etc/nginx/conf.d"
        },
        {
          "sourceVolume": "awseb-logs-nginx-proxy",
          "containerPath": "/var/log/nginx"
        }
      ]
    }
  ]
}

Following is the exception -

2019-02-08 14:42:27.580  INFO 22 --- [nio-8100-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client currency-exchange-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=currency-exchange-service,current list of Servers=[bb0780eaed0b:8000],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;  Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:bb0780eaed0b:8000; Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 00:00:00 GMT 1970;  First connection made: Thu Jan 01 00:00:00 GMT 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@66d1ddb4
2019-02-08 14:42:27.868 ERROR 22 --- [nio-8100-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.RetryableException: bb0780eaed0b executing GET http://currency-exchange-service/currency-exchange/from/GBP/to/INR] with root cause

java.net.UnknownHostException: bb0780eaed0b
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) ~[na:1.8.0_191]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_191]
    at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_191]
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175) ~[na:1.8.0_191]
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) ~[na:1.8.0_191]
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:558) ~[na:1.8.0_191]
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:242) ~[na:1.8.0_191]
    at sun.net.www.http.HttpClient.New(HttpClient.java:339) ~[na:1.8.0_191]
    at sun.net.www.http.HttpClient.New(HttpClient.java:357) ~[na:1.8.0_191]
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220) ~[na:1.8.0_191]
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156) ~[na:1.8.0_191]
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050) ~[na:1.8.0_191]
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984) ~[na:1.8.0_191]
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564) ~[na:1.8.0_191]
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) ~[na:1.8.0_191]
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[na:1.8.0_191]
    at feign.Client$Default.convertResponse(Client.java:143) ~[feign-core-10.1.0.jar!/:na]
    at feign.Client$Default.execute(Client.java:68) ~[feign-core-10.1.0.jar!/:na]
    at org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:90) ~[spring-cloud-openfeign-core-2.1.0.RC3.jar!/:2.1.0.RC3]
    at org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:56) ~[spring-cloud-openfeign-core-2.1.0.RC3.jar!/:2.1.0.RC3]
    at com.netflix.client.AbstractLoadBalancerAwareClient$1.call(AbstractLoadBalancerAwareClient.java:104) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:303) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:287) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
    at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:231) ~[rxjava-1.3.8.jar!/:1.3.8]
    at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:228) ~[rxjava-1.3.8.jar!/:1.3.8]
    at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar!/:1.3.8]
    at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.drain(OnSubscribeConcatMap.java:286) ~[rxjava-1.3.8.jar!/:1.3.8]
    at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.onNext(OnSubscribeConcatMap.java:144) ~[rxjava-1.3.8.jar!/:1.3.8]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:185) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]

Solution

  • Ok, so I am able to resolve this by adding eureka.instance.preferIpAddress=true to all the microservices that registers itself to Eureka. The problem was occurring due to docker container id acting as the host which the system cannot resolve.