user5778069
user5778069

Reputation:

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?

enter image description here

Upvotes: 50

Views: 143756

Answers (24)

Abhishek Singh
Abhishek Singh

Reputation: 1517

if your Eureka Server is running fine, and this problem is coming while starting Eureka Client. Then make sure, don't add any context-path in Eureka Server. So your Eureka Server Url will be : http://localhost:8761/ (with root context /) and you will see the Ureka Server dashboard with above url. But in Eureka client service-url you need to add /eureka in the above path. see below:

Now in Eureka Client yaml file:

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/  #(notice here '/eureka' context path mandatory) 
    fetch-registry: true 
    register-with-eureka: true

Hope this helps anyone, I did this mistake and was getting same exception.

Upvotes: 0

Gurvir Singh
Gurvir Singh

Reputation: 1

It may be because of firewall is blocking the connection, for me when I added a config class in my discovery server service with below code, issue got resolved

 @Configuration
public class Config {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.csrf().ignoringRequestMatchers("/eureka/**");
        return httpSecurity.build();
    }

Upvotes: 0

Baliram Babar
Baliram Babar

Reputation: 1

I had to add these four lines to the application.properties, order sensitive

spring.application.name=ServiceRegistry
server.port=8761
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false

Upvotes: 0

Manjunatha D
Manjunatha D

Reputation: 1

I have faced similar issue in my eureka client service

I have changed the port on which the client service was running (from 8080 to 8082). It worked

Upvotes: 0

Gouranga Satapathy
Gouranga Satapathy

Reputation: 432

change the version

1.change the version 2. add in yml file -

eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false server: port: 8761

add @EnableEurekaServer at main class

Upvotes: 0

Naveen Gowda
Naveen Gowda

Reputation: 1

I was getting same error when I ran service registry project. Below step fixed my issue and able to run project.

Instead of using below:

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

Use This in application.properties:-

eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false

Upvotes: 0

prabhat kumar
prabhat kumar

Reputation: 139

use below property you can change ip based on yours eureka.client.service-url.defaultZone: ${eureka_url:http://localhost:8761/eureka}

Upvotes: 0

Alireza
Alireza

Reputation: 25

For me, the issue was in my build.gradle file. I just removed this part from my build.gradle file:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Then my gradle file changed to this:

buildscript {
    apply from:"../dependencies.gradle"
    ext {
        set('springBootVersion', "2.1.8.RELEASE")
        set('springCloudVersion',"Greenwich.SR2" )
        set('springCloudServicesVersion', "3.1.0.RELEASE")
        set('springBootAdminVersion','2.1.6')
    }
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE")
        classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
    }
}

Upvotes: 0

nomaanhusain
nomaanhusain

Reputation: 23

Stater config is needed sometimes, to pom.xml add

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

In application.properties add

spring.config.import=optional:configserver:http://localhost:8888

Upvotes: 0

iwritecomeinmymind
iwritecomeinmymind

Reputation: 376

Let's set aside the answers given above. Maybe you didn't get the server that has @EnableEurekaServerannotation program up. :)

Upvotes: 0

neetu shaky
neetu shaky

Reputation: 11

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

eureka.instance.hostname=localhost

Upvotes: 0

Dmitry Rakovets
Dmitry Rakovets

Reputation: 589

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

Upvotes: 5

Prashant K
Prashant K

Reputation: 909

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.

Upvotes: 1

Muhammed Ozdogan
Muhammed Ozdogan

Reputation: 5867

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.

Upvotes: 4

Vaibs
Vaibs

Reputation: 2096

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

Upvotes: 1

Waqas Ahmed
Waqas Ahmed

Reputation: 5129

I was facing the same error when my Eureka client i.e 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

Upvotes: 6

Avinash Khadsan
Avinash Khadsan

Reputation: 497

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

Upvotes: 0

Srikanth Enjapuri
Srikanth Enjapuri

Reputation: 99

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

Upvotes: 1

Piyush Chaudhari
Piyush Chaudhari

Reputation: 1012

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

Upvotes: 2

itssaifurrehman
itssaifurrehman

Reputation: 41

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

Upvotes: 1

keith5140
keith5140

Reputation: 1394

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

Upvotes: 110

stanlee
stanlee

Reputation: 386

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.

Upvotes: 24

Ashish Kathait
Ashish Kathait

Reputation: 216

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.

Upvotes: 14

Faron
Faron

Reputation: 1393

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

Upvotes: 12

Related Questions