Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to register a service as Eureka Client

I'm trying to register a Microservice as Eureka Client in order to discover other Microservices, however, I follow the tutorial but nothing shows up in the Eureka Server. Below are code snippets:

  1. My demo application: a spring boot application running on localhost:9001, I want it become a Eureka Client, i.e., register itself as an instance and meanwhile has ability to discover other instances (I used the generic @EnableDiscoveryClientannotation and Spring Netflix Eureka is on the classpath):

    @RestController
    @SpringBootApplication
    @EnableDiscoveryClient
    public class DemoApplication {
    
    @RequestMapping("/") 
    String home() {
        return "This is a Demo project";
    }
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);  
    }
    }
    
  2. application.yml:

    server:
      port: 9001
    
    eureka:
      client:
        serviceUrl:
            defaultZone: http://localhost:8761/eureka/
    

The Eureka Server should be no problem since I have another Miscroservice running on localhost:8080 is successfully registered in the server. Just in case here is the application.yml for the Eureka Server:

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

Anyone see any problems here?

like image 682
OD Street Avatar asked Dec 05 '22 18:12

OD Street


2 Answers

The important thing is select the right import. I lost hours before realizing that:

This is the bare dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>

This is the starter pack dependency wanted in most case:

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

If you import the bare dependency, no errors or logs will show up but the service will not register to Eureka server.

Bottom line, make sure to double double check the dependencies: maybe you need the "starter pack" dependency for a Spring boot component.

like image 63
zerologiko Avatar answered Dec 20 '22 00:12

zerologiko


Problem solved, I didn't include dependency 'com.netflix.eureka:eureka-client:1.1.147' in my build.gradle.

like image 31
OD Street Avatar answered Dec 20 '22 01:12

OD Street