У меня ниже простая установка. 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)
Я уже проверил ответы на вопрос У балансировщика нагрузки нет доступного сервера для клиента Но у меня не сработало...
Что мне здесь не хватает?
/eureka/apps
на сервере eureka? - person spencergibb   schedule 29.04.2019