Giriş
Açıklaması şöyle
Açıklaması şöyle
... it will dynamically generate a proxy that will wrap the method and manage all calls through a thread pool of threads, mainly focused in handling remote calls
commandProperties - timeout
Timeout yani zaman aşımı değerini belirtmek için şuna benzer bir şey kullanılır
name = "execution.isolation.thread.timeoutInMilliseconds" value="6000"
Eğer fallback tanımlamazsak, zaman aşımı olursa şuna benzer bir hata alırız
"foo timed-out and fallback failed."
Örnek - timeout + fallback
Şöyle yaparız
@GetMapping@HystrixCommand(fallbackMethod=”defaultProductList”, commandProperties = {@HystrixProperty(name=”execution.isolation.thread.timeoutInMilliSeconds”,
value=”500”)})public String cloudProductList(@PathVariable long timeout) {RestTemplate restTemplate = new RestTemplate();URI uri = URI.create("http://localhost:8080/products");return restTemplate.getForObject(uri, String.class);}public List<String> defaultProductList() {return Arrays.asList("product");}
fallbackMethod Alanı
Örnek - timeout + fallback
Şöyle yaparız.
Şöyle yaparız.
@SpringBootApplication
@EnableHystrix
@RestController
public class DemoHystrixApplication {
  public static void main(String[] args) {
    SpringApplication.run(DemoHystrixApplication.class, args);
  }
  @RequestMapping(value = "/")
  @HystrixCommand(fallbackMethod = "fallback", commandProperties = {
    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",
                     value = "1000")
  })
  public String hello() throws InterruptedException {
    Thread.sleep(3000);
    return "HELLO Hystrix";
  }
  private String fallback() {
    return "Fallback";
  }
}
 
Hiç yorum yok:
Yorum Gönder