Java com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46131196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:15:53  来源:igfitidea点击:

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

javaspring-bootmicroservices

提问by

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.

我对微服务非常陌生,并尝试从链接运行代码:https: //dzone.com/articles/advanced-microservices-security-with-spring-and-oa。当我简单地运行代码时,我看到以下错误出现。

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

在此处输入图片说明

回答by Faron

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 注册,但 Eureka 没有响应。您可以通过将以下内容添加到 application.yml 来启动 Eureka 的实例或禁用自动注册。

eureka:
  client:
    register-with-eureka: false

回答by ashish kathait

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

您需要创建 Eureka Registry Server,这是另一个微服务。它是 SpringBoot 应用程序的主类,应该有 @EnableEurekaServer 注释。

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

然后在您的 Eureka 客户端中,您必须在 appliation.yml 中提及注册表服务器 URL,如下所示:

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.

defaultzone 应该保存您的 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.

完成所有这些配置后,您需要启动 Eureka Registry 微服务,然后才能启动 Eureka 客户端。一旦您的注册表启动,您将不会遇到此异常。

回答by stanlee

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

发生这种情况是因为它正在尝试连接到任何已知服务器,因此为了阻止该错误,已知服务器是端口 8761 上的 eureka 服务器,这是其默认端口,您必须使用以下内容更新 application.properties

server.port=8761

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

为了避免尤里卡注册自己,你将它添加到 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.

确保启用了 EurekaServer,例如使用 spring boot 在主类上编写以下内容。

@EnableEurekaServer

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

请原谅我提供使用 .properties 文件的解决方案,但这是我使用的,但 .yml 配置不应该有太大的不同。

回答by xuezhongyu01

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

我发现我必须将这两个应用程序添加到 appllication.properties 中,它才能工作。只有一个是不够的。

eureka.client.register-with-eureka=false

eureka.client.fetch-registry=false

回答by itssaifurrehman

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.

在 ZuulLoggingFiler.java 中查找 filterType()。我有同样的问题。然后我看到我的过滤器返回 null。所以我将其更改为“发布”并且它起作用了。

@Override
public String filterType() {
    // TODO Auto-generated method stub
    return "post";
}

回答by Piyush Chaudhari

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

如果您的 eureka 服务器在没有用户名和密码的情况下部署/运行,请使用以下属性。

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

回答by Srikanth Enjapuri

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

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

回答by Avinash Khadsan

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

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

回答by Waqas Ahmed

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

当我的 Eureka 客户端(即微服务)尝试向 Eureka 服务器注册自己时,我遇到了同样的错误。

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 :.

1) defaultZone 地址不正确,要么拼写错误,要么在:之后缺少空格。

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.

2) 在 Eureka 服务器上实现的 Spring security 要求每个请求都发送一个有效的 CSRF 令牌。Eureka 客户端通常不会拥有有效的跨站点请求伪造 (CSRF) 令牌。因此,您需要为 /eureka/** 端点禁用此要求。

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

在使用以下代码行禁用 CSRF 令牌后,我的 Eureka 客户端成功地向 Eureka 服务器注册了它们。

@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.

下面还有来自 spring 文档的链接。

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

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