0

I am developing a microservice apps using spring, spring boot, eureka (for service discovery) and ribbon.

My application on consist of three services client, server and eureka-server

client and server both get registered with eureka-server and later client makes call to server using the eureka service discovery.

I am able to locally run the application and things works perfectly fine.

But when deploying on aws things go haywire.

Steps followed

  • Three ec2 instance in same security group.
  • Each microservice is running as docker container with properly exposed ports.
  • One ec2 instance has elastic ip. Eureka-server container is running on it.
  • Client and Server container are deployed on other two ec2 instances.

Result

When using ECS

  • Client and server are able to register themselves with Eureka-server.

    Application AMIs    Availability Zones  Status
    HELLO-CLIENT    n/a (1) (1) UP (1) - 3fcd1c92386d:hello-client:8071
    HELLO-SERVER    n/a (1) (1) UP (1) - 6a5d643b32e1:hello-server:8072
    
  • When hitting client endpoint getting java.net.UnknownHostException.

    Whitelabel Error Page
    
    This application has no explicit mapping for /error,so you are seeing
    this as a fallback.
    
    Sun Sep 10 08:38:17 GMT 2017
    There was an unexpected error (type=Internal Server Error, status=500).
    I/O error on GET request for "http://hello-server/hello/server/":6a5d643b32e1; 
    nested exception is java.net.UnknownHostException: 
    6a5d643b32e1
    

When using Docker Swarm

  • Client and server are able to register themselves with Eureka-server.

    Application AMIs    Availability Zones  Status
    HELLO-CLIENT    n/a (1) (1) UP (1) - ip-10-255-0-5.ap-south-1.compute.internal:hello-client:8071
    HELLO-SERVER    n/a (1) (1) UP (1) - ip-10-255-0-6.ap-south-1.compute.internal:hello-server:8072
    
  • When hitting client endpoint getting Connection timed out.

    Whitelabel Error Page

    This application has no explicit mapping for /error, so you are seeing 
    this as a fallback.
    
    Sun Sep 10 11:22:20 GMT 2017
    There was an unexpected error (type=Internal Server Error, status=500).
    I/O error on GET request for "http://hello-server/hello/server/": 
    Operation timed out (Connection timed out); nested exception is 
    java.net.ConnectException: Operation timed out (Connection timed out)
    

Eureka Configuration

    application.properties
    --------
    spring.application.name=eureka-server
    server.port=8070

    bootstrap.yml
    --------
    eureka:
      client:
        registerWithEureka: false
        fetchRegistry: false
        server:
          waitTimeInMsWhenSyncEmpty: 0
        service-url:
          defaultZone: http://<Elastic IP of eureka server>:8070/eureka

Server configuration

    application.properties
    --------
    spring.application.name=hello-server
    server.port=8072

    bootstrap.yml
    --------
    eureka:
      client:
        service-url:
          defaultZone: http://<Elastic IP of eureka server>:8070/eureka

Client configuration

    application.properties
    --------
    spring.application.name=hello-client
    server.port=8071

    bootstrap.yml
    --------
    eureka:
      client:
        service-url:
          defaultZone: http://<Elastic IP of eureka server>:8070/eureka

Rest Client configuration

    Resource.java
    ---------------------------------
    @Autowired
    RestTemplate restTemplate;

    @GetMapping
    @RequestMapping("/hello/client")
    public String hello(){
            String uri = "http://hello-server/hello/server/";
            return restTemplate.getForObject(uri, String.class);
    }


    Config.java
    ----------------------------
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){
    return  new RestTemplate();
    }
sanjaykumar81
  • 435
  • 1
  • 6
  • 13
  • How do you register to eureka. Can you share your application.properties files. And how is your docker set up? Are you using docker-swarm or compose? – barbakini Sep 10 '17 at 10:47
  • Hi Barbakini, I have added the configuration detail above. – sanjaykumar81 Sep 10 '17 at 11:24
  • And how is your `RestTemplate`configuration in client? Are you directly writing ip or docker container name or eureka registered name of server? most probably, your problem is in client service. I think client does not aski about server service to eureka and try to connect directly with a written name or ip address that cannot be resolved. – barbakini Sep 10 '17 at 11:35
  • Are the dockers in the same network? if not you need to make both being in the same, otherwhise they can't see each other – juanlumn Sep 10 '17 at 11:35
  • @juanlumm obviously containers see each other because both server and client can register themselves to eureka. – barbakini Sep 10 '17 at 11:38
  • Hi Barbakini, I have added the client configuration in the question. – sanjaykumar81 Sep 10 '17 at 11:44
  • It all looks like okay. I have no more guess, sorry. – barbakini Sep 10 '17 at 12:05

1 Answers1

0

I am able to resolve this problem. Here the problem is system is trying to ping the Eureka client using the docker container id as host which system cannot resolve. In the microservice configuration set the eureka.instance.preferIpAddress=true for all the services. It will definitely solve the problem.