com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Asked Answered
M

22

49

I am very new to the microservices and trying to run the code from link: https://dzone.com/articles/advanced-microservices-security-with-spring-and-oa . When I simply run the code I see the following error comes.

What is the issue ?

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
    at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1030) [eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:944) [eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1468) [eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1435) [eureka-client-1.4.12.jar:1.4.12]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [na:1.8.0_144]
    at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_144]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_144]

2017-09-09 18:53:11.909 ERROR 16268 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error

I have not installed anything special on to the system. Please let me know what do I need to install?

enter image description here

Mackenziemackerel answered 9/9, 2017 at 13:26 Comment(0)
M
109

I find I have to add these two applications to the appllication.properties,it can work.Only one is not enough.

eureka.client.register-with-eureka=false

eureka.client.fetch-registry=false
Mandamandaean answered 11/6, 2018 at 5:46 Comment(5)
This helped me resolve my problem, thanks for this @xuezhongyu01Jubbulpore
Thanks ... This is the correct answer ... eureka.client.fetch-registry=false included this line in my eureka microservice.Vedette
Yeah, but this essentially makes this client unable to be discoverable. Is that ideal? Maybe for this case... For me, it was essentially: 1) start the @EnableEurekaServer app first; 2) Start any @EurekaDiscoveryClient apps afterward. This is mostly just a timing issue (tries to connect, fails, tries again, fails, tries again, succeeds)Henn
To clarify, the two properties above are used inside the eureka server, not the client. This prevents the server from registering itself.Scratch
Thanks eureka.client.register-with-eureka=false resolved my issue.Isoleucine
C
24

This is happening because it is trying to connect to any known server, so to stop that error, a known server is eureka server on port 8761 which is its default port, you will have to update the application.properties with following

server.port=8761

To avoid eureka from registering itself, you add this to the application.properties

eureka.client.register-with-eureka=false

Ensure that EurekaServer is enabled, for example using spring boot you write the below on the main class.

@EnableEurekaServer

Please pardon me providing solution using .properties file but that is what i work with but .yml configurations shouldn't be too different.

Cimbalom answered 29/5, 2018 at 19:41 Comment(0)
A
14

You need to create Eureka Registry Server which is another microservice. It's main class incase of an SpringBoot application, should have @EnableEurekaServer annotation.

Then in your Eureka Client you will have to mention the Registry server URL in appliation.yml as below :

spring:
  application:
    name: stock-service

server:
  port: 8083


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

where defaultzone should hold the value of your Eureka Registry.

Once you do all these configurations you need to Get the Eureka Registry microservice up and then you can get the Eureka client up. Once your Registry is up you will not face this exception.

Alimentary answered 3/2, 2018 at 20:23 Comment(0)
P
11

This particular message is just a warning. Your application is attempting to register with Eureka but Eureka is not responding. You can either start an instance of Eureka or disable the automatic registration by adding the following to your application.yml.

eureka:
  client:
    register-with-eureka: false
Peephole answered 9/9, 2017 at 18:10 Comment(2)
oh, I think I dont have Eureka installed on my windows box ? Is that the problem ? Do I need to installed that ?Mackenziemackerel
You probably do not need it for what you are doing. Just disable it so you do not see a message every 5 seconds. If you would like to learn more about Eureka, start here (spring.io/guides/gs/service-registration-and-discovery)Peephole
O
6

I was facing the same error when my Eureka client i.e microservice trying to register herself with Eureka Server.

Client registration eureka service failure registration failed Cannot execute request on any known server

This error message comes because of following two possibilities.

1) The defaultZone address is incorrect , either its misspelled or the space is missing after :.

2) Spring security implemented on Eureka server require a valid CSRF token be sent with every request. Eureka clients will not generally possess a valid cross site request forgery (CSRF) token. So you will need to disable this requirement for the /eureka/** endpoints.

After disabling the CSRF token with follwoing line of code my Eureka client successfully register them selves with Eureka Server.

@EnableWebSecurity
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().ignoringAntMatchers("/eureka/**");
        super.configure(http);
    }
}

Also below is the link from spring docs.

https://cloud.spring.io/spring-cloud-static/Greenwich.SR2/single/spring-cloud.html#_securing_the_eureka_server

Overweight answered 15/4, 2020 at 7:28 Comment(2)
Can you please tell us spring boot and spring cloud versions you have tried with? I have the same issue and the culprit is spring security. I have tried your solution but no difference. I have already looked at docs and github.com/spring-cloud/spring-cloud-netflix/issues/2754. no difference. By the way my spring-boot version is: 2.5.2 and spring-cloud version is: 2020.0.3Pretorius
@MortezaBandi my fixed solution was with spring-boot 2.2.6.RELEASE and spring-cloud Hoxton.SR3Overweight
C
5

Version for dependencies:

  • Spring Boot: 2.5.6
  • Spring Cloud: 2020.0.4

Eureka Server App

application.yaml

server:
  port: 8010
eureka:
  client:
    fetch-registry: false
    register-with-eureka: false
    service-url:
      defaultZone: http://localhost:8010/eureka

MyEurekaServerApplication.java

@EnableEurekaServer
@SpringBootApplication
public class MyEurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyEurekaServerApplication.class, args);
    }
}

Eureka Client App

application.yaml

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8010/eureka

If you use default-zone instead of defaultZone, then the Eureka Client App throws an exception when registering on the Eureka Server.

MyEurekaClientApplication.java

@EnableEurekaClient
@SpringBootApplication
public class MyEurekaClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyEurekaClientApplication.class, args);
    }
}
Coalfield answered 10/11, 2021 at 3:24 Comment(0)
A
4

I got the same error. In my case, in the application.properties file of my client application I misspelled the defaultZone word. I wrote default-zone but it must be defaultZone.

Client App application.properties:

eureka.client.service-url.defaultZone=http://localhost:8030/eureka/

Hostname and port may differ in your case.

Animadversion answered 2/5, 2021 at 20:18 Comment(0)
L
2

If your eureka server is deployed/running without username and password use below properties.

spring.application.name=Hello-World
eureka.client.serviceUrl.defaultZone=http://eurekaserver:password@localhost:9100/eureka
server.port=9200
eureka.client.fetch-registry=true

If your eureka server is deployed/running with username and password use below properties.

spring.application.name=Hello-World
eureka.client.serviceUrl.defaultZone=http://eurekaserverusername:eurekaserverpassword@localhost:9100/eureka
server.port=9200
eureka.client.fetch-registry=true
Luce answered 5/1, 2020 at 10:43 Comment(0)
R
1

Look for the filterType() in ZuulLoggingFiler.java. I had the same problem. Then i saw my filter was returning null. so I changed it to "post" and it worked.

@Override
public String filterType() {
    // TODO Auto-generated method stub
    return "post";
}
Retread answered 11/10, 2019 at 15:50 Comment(0)
A
1

Check your URL and port number of eureka server provided in "eureka.client.serviceUrl.defaultZone" property.

Ascensive answered 16/2, 2020 at 13:23 Comment(0)
C
1

Similar error will be thrown when you have misspelled anything in the value of defaultZone. For ex: someone has misspelled eureka to euraka. Double check it.

defaultZone : http://localhost:8761/eureka
Cribb answered 6/6, 2020 at 15:28 Comment(0)
S
1

Adding the following lines in application.properties solved it:

server.port=8761

eureka.client.register-with-eureka=false

eureka.client.fetch-registry=false

The first one is optional.

The other two properties are used to tell Eureka Server that "Hey, you're the only Eureka Server in this context, don't try to find other Eureka Servers"

If we don't mention these, our Eureka Server will try to find and register itself on other Eureka Servers and will eventually throw the Transport Exception.

Seamanship answered 9/1, 2022 at 12:56 Comment(0)
O
0

for me its working after connecting to internet because it need to download some dependence first time.

Overbuild answered 3/4, 2020 at 7:32 Comment(0)
P
0

Try to add this property in your microservice which you want to connect with the naming server:

eureka.instance.hostname=localhost
Poppo answered 8/12, 2022 at 8:55 Comment(0)
D
0

Let's set aside the answers given above. Maybe you didn't get the server that has @EnableEurekaServerannotation program up. :)

Daleth answered 5/2, 2023 at 2:33 Comment(0)
B
0

Stater config is needed sometimes, to pom.xml add

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

In application.properties add

spring.config.import=optional:configserver:http://localhost:8888
Brueghel answered 23/2, 2023 at 9:47 Comment(0)
L
0

For me, the issue was in my build.gradle file. I just removed this part from my build.gradle file:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Then my gradle file changed to this:

buildscript {
    apply from:"../dependencies.gradle"
    ext {
        set('springBootVersion', "2.1.8.RELEASE")
        set('springCloudVersion',"Greenwich.SR2" )
        set('springCloudServicesVersion', "3.1.0.RELEASE")
        set('springBootAdminVersion','2.1.6')
    }
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE")
        classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
    }
}
Lynnet answered 6/4, 2023 at 11:1 Comment(0)
R
0

use below property you can change ip based on yours eureka.client.service-url.defaultZone: ${eureka_url:http://localhost:8761/eureka}

Reimer answered 6/9, 2023 at 6:59 Comment(0)
A
0

I was getting same error when I ran service registry project. Below step fixed my issue and able to run project.

Instead of using below:

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

Use This in application.properties:-

eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
Agee answered 14/10, 2023 at 11:46 Comment(0)
D
0

change the version

1.change the version 2. add in yml file -

eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false server: port: 8761

add @EnableEurekaServer at main class

Dewberry answered 24/12, 2023 at 18:52 Comment(0)
T
0

I have faced similar issue in my eureka client service

I have changed the port on which the client service was running (from 8080 to 8082). It worked

Transmitter answered 13/4, 2024 at 11:59 Comment(0)
G
0

I had to add these four lines to the application.properties, order sensitive

spring.application.name=ServiceRegistry
server.port=8761
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
Gesticulation answered 25/4, 2024 at 14:35 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.