Spring-cloud-netflix: Connection refused while trying to register eureka-clients

Created on 31 Aug 2016  路  21Comments  路  Source: spring-cloud/spring-cloud-netflix

I have one eureka-server running on a linux(testsrv1) machine. I'm able to register services when they run on the same linux machine. Now I want to register a service running on my localhost. But I'm bot able to register this service.
I get this exception:

2016-08-31 09:17:31.917 ERROR 27105 --- [freshExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
Caused by: java.net.ConnectException: Connection refused
2016-08-31 09:17:31.917  WARN 27105 --- [freshExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failure
2016-08-31 09:17:31.918 ERROR 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_RESERVATION-SERVICE/testsrv1.myDomain.lan:reservation-service:8002 - was unable to refresh its cache! status = Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
2016-08-31 09:17:31.924 ERROR 27105 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error

My Eureka-Server has this properties:

spring.application.name=eureka-service
spring.cloud.config.uri=http://myLocalMachine.myDomain.lan:8888
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

My Client-service has this properties:

spring:
  application:
    name: reservation-service
  cloud:
    config:
      uri: http://myLocalMachine.myDomain.lan:8888
server:
  port: 8002
eureka:
  client:
    service-url:
     defaultzone: http://testsrv1:8761/eureka/

The Eureka-Server is abel to reach the cloud-config-files from my config-service running on localhost.

Is there any configuration missing or do I need the cloud foundry?

Thanks in advance!

Most helpful comment

After days, looking thousand times on the same config file I realized the issue. At the end it was just a misspelling of defaultzone. After changing it to defaultZone everything works like expected.
Thank you very much for your time.

All 21 comments

There are no constraints on the eureka server from accepting connection from the outside. It's just a standard spring boot app. No cloud foundry needed. There must be some problem with your environment. Can localhost reach testsrv1?

Yes I can reach the eureka dashboard from my localhost for example. Eureka server can also reach the config-service running on my localhost. So I think this should be fine. But from your point of view the configuration files are good? And in theorie it should work as it is configured?

config looks fine. Not sure how I'd help debug a connection refused. My guess is a sample project might not even help, but could try.

There wouldn't happen to be any configuration from the config server that is overriding the defaultzone property, is there?

First, thanks for your responses. At the end all the services are sample projects and I also think a connection reset is very hard to reproduce. But I will show you my Spring-boot-application configuration. Maybe I missed some annotation on application level.

Eureka:

@SpringBootApplication
@EnableEurekaServer
public class EurekaServiceApplication {

Service:

@SpringBootApplication
@EnableDiscoveryClient
@EnableEurekaClient
public class ReservationServiceApplication {

When I run all my services and eureka on the same host (local or linux machine) everything works fine.
I will check if there is any overriding property and will also try to check the connectivity or use other server.

In the service you don't need both @EnableDiscoveryClient and @EnableEurekaClient one or the other should do.

I'm still checking why I get the connection reset exception. Just captured some traffic using wireshark and RawCap.
I can see http requests from my service to the config server:

GET /reservation-service/default HTTP/1.1
Accept: application/json, application/*+json
User-Agent: Java/1.8.0_77
Host: KBHWS242.eurotours.lan:8888
Connection: keep-alive

HTTP/1.1 200 
X-Application-Context: application:8888
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 02 Sep 2016 13:54:07 GMT

123
{"name":"reservation-service","profiles":["default"],"label":"master","version":"a30016147d52b0bcf71f20ee22b5751417ddebe1","propertySources":[{"name":"C:\\DATA\\micro-service-config/reservation-service.yml","source":{"eureka.client.service-url.defaultzone":"http://testsrv1:8761/eureka/"}}]}

So the right configuration is sent back to the service. But I do not see any requests to the eureka service running on testsrv1 (linux machine). The service should also send some http requests to testsrv1, right?

What I see are tcp calls to localhost:8761 which could describe the connection reset error. And I do not see any tcp/http request to testsrv1(or IP of it). Seems a litte bit that the config is not right updated!?

Maybe showing looking at the output of '/env' to see the environment of the app might help. Can at least verify that the correct defaultzone location is being used.

After days, looking thousand times on the same config file I realized the issue. At the end it was just a misspelling of defaultzone. After changing it to defaultZone everything works like expected.
Thank you very much for your time.

Hi All

I have tried creating the eureka discovery server but still facing the issue.

application.yml
spring:
application:
name: VehicleEureka-client

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

  **pom.xml**


xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

<groupId>com.Vehicle</groupId>
<artifactId>VehicleEureka-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>VehicleEureka-client</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Edgware.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>


Client
@EnableDiscoveryClient
@SpringBootApplication
public class VehicleEurekaClientApplication {

public static void main(String[] args) {
    SpringApplication.run(VehicleEurekaClientApplication.class, args);
}

}

Error:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Request execution failed with message: java.net.ConnectException: Connection refused: connect

Can one please suggest what has to be changed _Need help here_

@alok001 please stop repeating your issue in multiple places, this is the third or fourth one. It's holidays in the US and the weekend, please be patient.

Guys, I was also facing same issue. I solved this issue with below process.

Error:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Request execution failed with message: java.net.ConnectException: Connection refused: connect

Solution:

http://sachin4java.blogspot.in/2017/12/cndstdredirectingeurekahttpclient.html

Hope, this will save your time.

defaultZone is a key in a map, therefore not subject to boot relaxed binding. It's format sensitive

i am getting the same error while starting eureka server. please help me to resolve this issue

My pom.xml


org.springframework.boot
spring-boot-starter-parent
1.5.6.RELEASE

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Dalston.SR4</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

application.yml

spring:
application:
name: cloud-service

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

client

@EnableEurekaServer
@SpringBootApplication
public class MyController {

public static void main(String[] args) {
    SpringApplication.run(MyController.class, args);

}

}

error

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.6.2.jar:1.6.2]
at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509) ~[jersey-client-1.19.1.jar:1.19.1]

@rahula072 -

Can you please make it

application.yml

spring:
application:
name: cloud-service

eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://127.0.0.1:9002/eureka/
instance:
hostname: localhost

also, make sure your eureka server started.

for more details, I have created series, you can go through it.
http://sachin4java.blogspot.in/p/microservices.html

@ranesaci

i have tried that but getting the same error and i have not written any client yet. This error i am getting while starting eureka server.

@rahula072
for eureka server, make your application.properties as shown below:

server.port=9002
spring.application.name=eureka-service

Eureka server

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF

@ranesaci

Thanks you so much for your help. Now Eureka server is up and running ,thanks to u.

After a lot of googling and getting no joy I ended up just changing the eureka-service server.port value in the application.properties file or its equivalent in application.yml file and it fixed the issue.

Well such a simple thing, was getting same issue and it was this word in bold
eureka.client.service-url.defaultZone=http://localhost:9999/eureka/

After days, looking thousand times on the same config file I realized the issue. At the end it was just a misspelling of defaultzone. After changing it to defaultZone everything works like expected.
Thank you very much for your time.

Thanks! you save my time 馃憤

Was this page helpful?
0 / 5 - 0 ratings