joshlong-attic / service-registration-and-discovery

A repository for a blog on how Spring Cloud promotes resilient service-to-service calls through service registries and service discovery
Apache License 2.0
98 stars 97 forks source link

Could not resolve host: peer1-service but could see in eureka dashboard #5

Open VravikumarV opened 6 years ago

VravikumarV commented 6 years ago

Hi,

We are refactoring existing monolithic based application to micro-services and we decided to use the following spring cloud (Netflix) version and end up with "Could not resolve host: peer1-service" on curl for registered micro service with "spring:application:name: peer1-service".

Could some one help me here please as I struck up with this for a long time by spending on google and trying different ways...

JDK 8 Spring boot 2.0.0.RELEASE Spring cloud: Finchley.M8

  1. Eureka Server with below configuration (Also annotated with @EnableEurekaServer):

spring: application: name: eureka-service

eureka: client: register-with-eureka: false fetch-registry: false server: wait-time-in-ms-when-sync-empty: 0

  1. peer1-service & peer2-service has same configurations except service name & port

spring: application: name: peer1-service

server: port: 8282

eureka: instance: hostname: localhost client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8080/eureka

This issue has come up when I start using service name which register with eureka discovery service where as if I use localhost instead of peer1-service / peer2-service, its working fine. Then I understood that something went wrong with discovery of service based on the name what I provided in application.yaml

The logs for reference (Same as for peer2-service)...

  1. Eureka Server logs:

2018-03-07 23:37:10.551 WARN 7327 --- [nio-8080-exec-2] c.n.e.registry.AbstractInstanceRegistry : DS: Registry: lease doesn't exist, registering resource: PEER1-SERVICE - venkatas-mbp:peer1-service:8282 2018-03-07 23:37:10.551 WARN 7327 --- [nio-8080-exec-2] c.n.eureka.resources.InstanceResource : Not Found (Renew): PEER1-SERVICE - venkatas-mbp:peer1-service:8282 2018-03-07 23:37:10.587 INFO 7327 --- [nio-8080-exec-3] c.n.e.registry.AbstractInstanceRegistry : Registered instance PEER1-SERVICE/venkatas-mbp:peer1-service:8282 with status UP (replication=false) 2018-03-07 23:37:10.587 INFO 7327 --- [nio-8080-exec-4] c.n.e.registry.AbstractInstanceRegistry : Registered instance PEER1-SERVICE/venkatas-mbp:peer1-service:8282 with status UP (replication=false) 2018-03-07 23:37:11.139 ERROR 7327 --- [get_localhost-1] c.n.e.cluster.ReplicationTaskProcessor : Network level connection to peer localhost; retrying after delay

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused) at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1] at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.8.6.jar:1.8.6]

  1. PEER2-SERVICE log trace (same as PEER1-SERVICE)

2018-03-07 23:37:16.343 INFO 7324 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA2-SERVICE/venkatas-mbp:eureka2-service:8181 - Re-registering apps/EUREKA2-SERVICE 2018-03-07 23:37:16.343 INFO 7324 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA2-SERVICE/venkatas-mbp:eureka2-service:8181: registering service... 2018-03-07 23:37:16.357 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : The response status is 200 2018-03-07 23:37:16.392 INFO 7324 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA2-SERVICE/venkatas-mbp:eureka2-service:8181 - registration status: 204 2018-03-07 23:37:16.392 INFO 7324 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA2-SERVICE/venkatas-mbp:eureka2-service:8181 - registration status: 204 2018-03-07 23:37:46.362 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Disable delta property : false 2018-03-07 23:37:46.362 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null 2018-03-07 23:37:46.362 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false 2018-03-07 23:37:46.362 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Application is null : false 2018-03-07 23:37:46.362 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true 2018-03-07 23:37:46.362 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Application version is -1: false 2018-03-07 23:37:46.362 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 2018-03-07 23:37:46.395 INFO 7324 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : The response status is 200

ShahanshahAli commented 5 years ago

This is duplicate of this seems: https://github.com/spring-cloud/spring-cloud-netflix/issues/2893