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();
}