Search code examples
spring-bootspring-cloudnetflix-zuulnetflix-eureka

Spring Cloud : Zuul throwing "Load balancer does not have available server for client"


I am trying to get a simple microservice to register to the Eureka Server and then have Zuul proxy to the microservice. I got the microservice to register to the Eureka Server. However, whenever I bring the Zuul service up I see that it is not registering to the Eureka Server. Whenever I try to route to the microservice I get the below exception:

Load balancer does not have available server for client: microservice

I am not able to figure out where the issue is. Any help would be greatly appreciated

Below are my Spring Boot classes for each of these components.

Microservice Components

MicroserviceApplication.java

@SpringBootApplication(scanBasePackages = { "some.package.controller", "some.package.service" })
@EnableEurekaClient
@EnableJpaRepositories("some.package.repository")
@EntityScan("some.package.entity")
public class MicroserviceApplication {

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

}

bootstrap.yml

server:
  port: 8090

info:
  component: Core Services

spring:
  application:
    name: microservice

application.yml

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
    healthcheck:
      enabled: true
    lease:
      duration: 5

#some other logging and jpa properties below

Eureka Server Components

EurekaServerApplication.java

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

}

bootstrap.yml

spring:
  application:
    name: discovery-server

application.yml

server:
  port: 8761

info:
  component: Discovery Server

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

API Gateway Components

ZuulGatewayApplication.java

@SpringBootApplication
@EnableZuulProxy
public class ZuulGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(ZuulGatewayApplication.class, args);
    }

    @Bean
    public ZuulGatewayPreFilter gatewayPreFilter() {
        return new ZuulGatewayPreFilter();
    }
}

bootstrap.yml

spring:
  application:
    name: api-gateway

application.yml

server:
  port: 8888

info:
  component: API Gateway

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

zuul:
  routes:
    microservice: 
      path: /microservice/**
      serviceId: microservice

Solution

  • Adding @EnableEurekaClient solved this issue. The Zuul application is now discoverable in the Eureka server and is able to route requests.