Eureka客户端异常com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求

时间:2018-07-16 19:23:02

标签: spring-boot microservices spring-cloud netflix-eureka

我是微服务的新手。我正在尝试创建一个用于学习目的的小型应用程序。这是我的代码: EurekaServer-application.yml

    spring:
     application:
      name: EurekaServer

    server:
     port: 8080
     servlet:
      context-path: /EurekaServer

    eureka:
     client:
      fetch-registry: false
      register-with-eureka: false 

Eureka Server运行正常,我可以在http://localhost:8080/EurekaServer看到仪表板

EmployeeClient:application.yml在下面:

    spring:
     application:
      name: EmployeeClient

    server:
     port: 8586

    eureka:
     client: 
      serviceUrl:
       defaultZone: http://localhost:8080/EurekaServer

在最后一行中,我需要显式编写serviceUrl,因为在sts中按ctrl + space时,它不显示选项serviceUrl,但显示service-url,连字符。与defaultZone相同。我是否缺少某些jar或特定版本?

我的EmployeeClientApplication.java

    @EnableEurekaClient
    @SpringBootApplication
    public class EmployeeClientApplication {

       public static void main(String[] args) {
          SpringApplication.run(EmployeeClientApplication.class, args);
       }
    }

当我尝试运行EmployeeClientApplication.java时,出现以下异常:

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

我也尝试使用@EnableDiscoveryClient代替@EnableEurekaClient,但是没有运气。

EmployeeClient pom.xml的一部分如下:

    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>2.0.3.RELEASE</version>
       <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <java.version>1.8</java.version>
      <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>

   <dependencies>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <dependency>

我在哪里弄错了?

3 个答案:

答案 0 :(得分:2)

我认为,您必须将客户端属性中的默认区域从 / EurekaServer 更改为 / eureka

eureka:
     client: 
      serviceUrl:
       defaultZone: http://localhost:8080/eureka

“ / eureka”是向eureka注册中心注册服务的其余端点。 进行更改并尝试,它应该可以工作。

除此之外,如果您愿意更改UI仪表板的URL,则应使用eureka.dashboard.path属性。

答案 1 :(得分:0)

我必须在EmployeeClient application.yml中使用以下行

DataSet MyDataSet = new DataSet();
DataTable MyTable = MyDataSet.Tables.Add();

MyTable.Columns.Add("NumberVal", typeof(int));
MyTable.Columns.Add("TextVal", typeof(string));

Parallel.ForEach(RecordList, SingleRecord =>
{
    int IntVal = 0;
    string StringVal = string.Empty;

    IntVal = some logic;
    StringVal = SingleRecord + some logic; 

    MyTable.Rows.Add(IntVal, StringVal);
 });

答案 2 :(得分:0)

如果您已经在服务器的应用程序属性文件中添加了DiscoveryServer作为应用程序名称,则添加{ "size": 100, "query": { "bool": { "filter": [ { "term": { "some_category.keyword": "SOME CATEGORY Value" } } ], "should": [ { "match": { "field_1": "Some value" } }, { "match": { "field_2": "Some value" } } ] } } } 可以解决您的问题。