我正在尝试 hystrix 后备方法。在 localhost:8082 上,客户服务正在运行,它返回客户的名称。
如果客户服务关闭,则应调用回退方法。但它没有发生。
下面是代码片段。
请建议。
@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
public class DemoHystrixApplication {
@GetMapping("/")
public String name() {
String str = getCustomerName();
return str;
}
@HystrixCommand(fallbackMethod = "getFallbackCustomerName")
private String getCustomerName() {
RestTemplate restTemplate = new RestTemplate();
URI uri = URI.create("http://localhost:8082");
return restTemplate.getForObject(uri, String.class);
}
private String getFallbackCustomerName() {
System.out.println("coming inside fallback method");
return "Resillient Customer";
}
public static void main(String[] args) {
SpringApplication.run(DemoHystrixApplication.class, args);
}
}