Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.


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.


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

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


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

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.