9

I got to spring-boot application, an eureka server and an eureka client.

Here is my server configuration

server:
  port: 8761

spring:
  application:
    name: eureka-server

Here is my server code

package fr.maif.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableEurekaServer
@EnableZuulProxy
public class EurekaServerApplication {

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

Here is the client configuration

spring:
  application:
    name: eureka-client
server:
  port: 8083
eureka:
  client:
    serviceUrl:
      defaultZone: "http://localhost:8761/eureka"

Here is my client code

package fr.maif.eurekaclient;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientApplication {

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

The above works perfectly while the server port remains 8761, however when I try to change it (to 8080 or any other value) both in server port & client defaultZone configuration, the server continuously throws ConnectExceptions.

2017-08-10 15:54:31.424 ERROR 22219 --- [get_localhost-4] 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.6.2.jar:1.6.2]
    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.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
    at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.6.2.jar:1.6.2]
    at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:71) ~[eureka-core-1.6.2.jar:1.6.2]
    at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.6.2.jar:1.6.2]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_131]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_131]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_131]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_131]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_131]
    at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_131]
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.3.jar:4.5.3]
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
    ... 10 common frames omitted

What do I do wrong ?

Robert jardonneau
  • 434
  • 2
  • 4
  • 14
  • 1
    What happens when you access eureka with the browser in the new port? E.g. localhost:8080/ – alayor Aug 10 '17 at 14:02
  • Your comment helped me solve my issue : I had the eureka IHM but only the eureka client appeared in register application (not the server). I added `eureka.client.serviceUrl.defaultZone: "http://localhost:8080/eureka"` in my server config and it worked ! Thank you so much – Robert jardonneau Aug 10 '17 at 14:14

4 Answers4

24

Try this configuration:

  1. Server.
    server:
      port: 8080
    eureka:
      instance:
      hostname: localhost
      client:
        registerWithEureka: false
        fetchRegistry: false
          serviceUrl:
            defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  1. Client.
    spring:
      application:
      name: eureka-client
    server:
      port: 8083
    eureka:
      client:
      registerWithEureka: true
      fetchRegistry: true
      serviceUrl:
        defaultZone: http://localhost:8080/eureka/
Harry
  • 11,298
  • 1
  • 29
  • 43
Shchipunov
  • 460
  • 4
  • 11
  • 1
    Yup, `eureka.client.serviceUrl.defaultZone` was indeed missing in server config, as stated in previous comment. Thank you for your help =) – Robert jardonneau Aug 10 '17 at 14:25
  • Works for me too. – Adit choudhary Aug 07 '20 at 05:55
  • I don't think we need to provide the `defaultZone` in Server. I just changed to `server.port=3939` in `application.properties` file of Server and configure the `eureka.client.serviceUrl.defaultZone` in each of my Clients' as well as in ApiGateway's `application.properties` file with the port same as provided in the Server, i.e. `3939`. That worked for me! – Superman Jan 27 '22 at 19:46
0

Yep. as per Shchipunov comment the below properties do the job 1-eureka.instance.hostname=localhost (eureka server) 2-eureka.client.serviceUrl.defaultZone (client project)

ayman.mostafa
  • 451
  • 6
  • 5
0

You just need to add eureka.client.service-url.defaultZone=http://localhost:8080/eureka in your server application.yml file and remove quotes around url in both files.

remove quotes around url (Don't forget it)

Leni Code
  • 3
  • 2
0

The changes below work fine for me.

spring.application.name=netflix-eureka-naming-server 
# Eureka default port
#server.port=8761   
server.port=8762
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-Url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
Kirby
  • 15,127
  • 10
  • 89
  • 104