I have Below Simple Setup.
Spring Cloud Eureka Server
- and Two Services PricingService
and DiscountService
. Pricing Service calls-> DiscountService.
Server Setup
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
properties
spring.application.name=eureka-server
server.port=8761
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
DiscountService
@SpringBootApplication
@EnableDiscoveryClient
@Slf4j
public class DiscountServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscountServiceApplication.class, args);
}
}
@RestController
@RequestMapping("/discount/{product}")
@Slf4j
public class DiscountController{
@GetMapping
public int getDiscountPercentage(@PathVariable("product") String product){
log.info("Getting Discount for Product {}",product);
return 50;
}
}
spring.application.name=discount-service
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/
server.port=8081
Pricing Service
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class PricingServiceApplication {
public static void main(String[] args) {
SpringApplication.run(PricingServiceApplication.class, args);
}
}
@RestController
@Slf4j
class ServiceInstanceRestController {
@Autowired
private DiscountServiceClient discountServiceClient;
@GetMapping("/test/")
public String getPriceForProduct() {
log.info("getPriceForProduct");
int dscount = discountServiceClient.getDiscountPercentage("Test");
log.info("Discount is {}",dscount);
return "Price";
}
}
@FeignClient("discount-service")
interface DiscountServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/discount/{product}")
int getDiscountPercentage(@PathVariable("product") String product);
}
spring.application.name=pricing-service
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/
server.port=8080
eureka.client.fetchRegistry=true
While Calling Discount Service i am getting exception
com.netflix.client.ClientException: Load balancer does not have available server for client: discount-service
at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
I am using Spring Boot 2.1.4.RELEASE dependency used
spring-cloud-starter-netflix-eureka-client
spring-cloud-starter-openfeign
spring-cloud-starter-netflix-eureka-server-server (Fo Server)
I have already checked the answers for Load balancer does not have available server for client But did not work for me...
What I am missing here ?
/eureka/apps
say on the eureka server? – spencergibb