Spring Cloud Eureka + FeignClient + Ribbon: балансировщик нагрузки не имеет доступного сервера для клиента

У меня ниже простая установка. Spring Cloud Eureka Server- и две службы PricingService и DiscountService. Звонки в Службу ценообразования-> DiscountService.

Настройка сервера

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

свойства

spring.application.name=eureka-server
server.port=8761
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

введите здесь описание изображения

Служба скидок

@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

Служба ценообразования

@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

При звонке в службу скидок я получаю исключение

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]

Я использую зависимость Spring Boot 2.1.4.RELEASE

spring-cloud-starter-netflix-eureka-client
spring-cloud-starter-openfeign
spring-cloud-starter-netflix-eureka-server-server (Fo Server)

Я уже проверил ответы на вопрос У балансировщика нагрузки нет доступного сервера для клиента Но у меня не сработало...

Что мне здесь не хватает?


person Niraj Sonawane    schedule 29.04.2019    source источник
comment
Что говорит /eureka/apps на сервере eureka?   -  person spencergibb    schedule 29.04.2019
comment
Оба сервиса зарегистрированы   -  person Niraj Sonawane    schedule 29.04.2019
comment
У вас есть лента?   -  person spencergibb    schedule 22.05.2019
comment
Я изменил application.properties на application.yml, и это сработало. Не удалось отследить проблему   -  person Niraj Sonawane    schedule 23.05.2019


Ответы (1)


Это также требует зависимости исполнительного механизма

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Для получения более подробной информации перейдите по следующим ссылкам

  1. https://github.com/M-Thirumal/eureka-server
  2. https://github.com/M-Thirumal/eureka-client-1
  3. https://github.com/M-Thirumal/eureka-client-2
person Thirumal    schedule 04.03.2020