简体   繁体   中英

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

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?

在此处输入图像描述

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 ie 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

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.

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

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);
    }
}

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";
}

检查“eureka.client.serviceUrl.defaultZone”属性中提供的 eureka 服务器的 URL 和端口号。

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

Make sure your ribbon client is correct

package com.in28minutes.microservices.currencyconversionservice;

import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(name="curreenter code herency-exchange-service")
@RibbonClient(name="currency-exchange-service") 
public interface CurrencyExchangeServiceProxy { 
    @GetMapping("/currency-exchange/from/{from}/to/{to}")
    public CurrencyConversionBean retrieveExchangeValue
        (@PathVariable("from") String from, @PathVariable("to") String to); //mention correct pathvariables
}

对我来说,它在连接到互联网后工作,因为它需要第一次下载一些依赖项。

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.

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

eureka.instance.hostname=localhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM