ヒストリックフォールバックメソッドを試しています。 localhost:8082では、customer-serviceが実行され、顧客の名前が返されます。ヒストリックフォールバックメソッドが呼び出されません
カスタマーサービスが停止している場合は、フォールバックメソッドを呼び出す必要があります。しかし、それは起こっていない。
以下はコードスニペットです。
お勧めします。
@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);
}
}