Abhi
Abhi

Reputation: 113

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

I am new to microservices. I'm trying to create one small application for learning purpose. Here is my code: 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 is working fine and I am able to see the dashboard at http://localhost:8080/EurekaServer

EmployeeClient: application.yml is below:

    spring:
     application:
      name: EmployeeClient

    server:
     port: 8586

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

In last line I need to write serviceUrl explicitly as on pressing ctrl+space in sts it doesnot show option serviceUrl but it shows service-url, hyphen sign. And same with defaultZone. Am I missing some jar or specific version?

My EmployeeClientApplication.java

    @EnableEurekaClient
    @SpringBootApplication
    public class EmployeeClientApplication {

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

when I try to run EmployeeClientApplication.java it gives me below exception:

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

I also tried using @EnableDiscoveryClient in place of @EnableEurekaClient, but with no luck.

A part of EmployeeClient pom.xml is below:

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

Where I'm making a mistake?

Upvotes: 3

Views: 17714

Answers (3)

Gadhia Reema
Gadhia Reema

Reputation: 196

Adding eureka.instance.hostname=localhost can solve your issue, if you have added DiscoveryServer as the application name in the server's application properties file.

Upvotes: 0

Abhi
Abhi

Reputation: 113

I had to use below line in EmployeeClient application.yml

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

Upvotes: 1

Sachin
Sachin

Reputation: 541

I think, you will have to change default Zone in client property from /EurekaServer to /eureka

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

"/eureka" is the rest endpoint to register services to eureka registry. Make the changes and try, it should work.

In addition to this, if you are willing to change the UI dashboard url you should use eureka.dashboard.path property.

Upvotes: 7

Related Questions