简体   繁体   English

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

[英]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 .我对微服务非常陌生,并尝试从链接运行代码: 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.我发现我必须将这两个应用程序添加到 appllication.properties,它才能工作。只有一个是不够的。

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发生这种情况是因为它正在尝试连接到任何已知服务器,因此要停止该错误,已知服务器是端口 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 配置不应该有太大的不同。

You need to create Eureka Registry Server which is another microservice.您需要创建另一个微服务 Eureka Registry Server。 It's main class incase of an SpringBoot application, should have @EnableEurekaServer annotation.它是 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.完成所有这些配置后,您需要启动 Eureka Registry 微服务,然后才能启动 Eureka 客户端。 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.您的应用程序正在尝试向 Eureka 注册,但 Eureka 没有响应。 You can either start an instance of Eureka or disable the automatic registration by adding the following to your application.yml.您可以启动 Eureka 实例或通过将以下内容添加到 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.当我的 Eureka 客户端(即微服务试图向 Eureka Server 注册自己)时,我遇到了同样的错误。

Client registration eureka service failure registration failed Cannot execute request on any known server客户端注册eureka服务失败注册失败无法在任何已知服务器上执行请求

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. 2) 在 Eureka 服务器上实现的 Spring 安全性要求每个请求都发送一个有效的 CSRF 令牌。 Eureka clients will not generally possess a valid cross site request forgery (CSRF) token. Eureka 客户端通常不会拥有有效的跨站请求伪造 (CSRF) 令牌。 So you will need to disable this requirement for the /eureka/** endpoints.因此,您需要为 /eureka/** 端点禁用此要求。

After disabling the CSRF token with follwoing line of code my Eureka client successfully register them selves with Eureka Server.在使用以下代码行禁用 CSRF 令牌后,我的 Eureka 客户端成功地将它们自己注册到 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.下面还有来自 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

I got the same error.我得到了同样的错误。 In my case, in the application.properties file of my client application I misspelled the defaultZone word.就我而言,在我的客户端应用程序的application.properties文件中,我拼错了defaultZone单词。 I wrote default-zone but it must be defaultZone .我写了default-zone但它必须是defaultZone

Client App application.properties :客户端应用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.如果您的 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.如果您的 eureka 服务器使用用户名和密码部署/运行,请使用以下属性。

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春季启动2.5.6
  • Spring Cloud : 2020.0.4 2020.0.42020.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 .如果使用default-zone而不是defaultZone ,则Eureka Client AppEureka 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.在 ZuulLoggingFiler.java 中查找 filterType()。 I had the same problem.我有同样的问题。 Then i saw my filter was returning null.然后我看到我的过滤器返回 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.当您在 defaultZone 的值中拼错任何内容时,将引发类似的错误。 For ex: someone has misspelled eureka to euraka.例如:有人将 eureka 拼错为 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:在 application.properties 添加以下行解决了它:

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"其他两个属性用于告诉 Eureka Server “嘿,你是这个上下文中唯一的 Eureka Server,不要试图找到其他 Eureka Server”

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.如果我们不提及这些,我们的 Eureka Server 会尝试在其他 Eureka Server 上查找并注册自己,最终会抛出 Transport Exception。

Try to add this property in your microservice which you want to connect with the naming server:尝试在要与命名服务器连接的微服务中添加此属性:

eureka.instance.hostname=localhost

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EurekaServer com.netflix.discovery.shared.transport.TransportException:无法在 Docker 上的任何已知服务器上执行请求 - EurekaServer com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server on Docker Docker compose com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求 - Docker compose com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server 错误 - “com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求” - Error - "com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server" spring-boot eureka 客户端错误“无法在任何已知服务器上执行请求” - spring-boot eureka client error "Cannot execute request on any known server" 尝试构建简单的微服务时出现错误“无法在任何已知服务器上执行请求” - Trying to build simple Microservice getting error " Cannot execute request on any known server" Apache 运行 cassandra 和 .netflix.astyanax 库时出现 TransportException,没有任何特定的错误消息 - Apache TransportException when running cassandra and netflix.astyanax library without any specific error message 在启动时通过Netflix Eureka Discovery实现Spring Cloud Config Server循环依赖 - Spring Cloud Config Server Circular Dependency With Netflix Eureka Discovery on Startup net.schmizz.sshj.transport.TransportException:无法达成和解 - net.schmizz.sshj.transport.TransportException: Unable to reach a settlement 如何使用Netflix / Eureka Service的发现信息在Netflix / Zuul和Netflix / Ribbon中启用自动路由? - How to enable automatic routing in Netflix/Zuul and Netflix/Ribbon with discovery information from Netflix/Eureka Service? 响应类中的com.netflix.feign NullPointerException - com.netflix.feign NullPointerException in Response class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM