Circuit Breaker - Hystrix

Hystrix 적용하기

@HystrixCommand 
public String anyMethodWithExternalDependency() {
 URI uri = URI.create("http://172.32.1.22:8090/recommended"); 
 String result = this.restTemplate.getForObject(uri, String.class); 
 return result; 
}

Hystrix - Circuit Breaker

@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback") 
public String anyMethodWithExternalDependency1() {
 URI uri = URI.create("http://172.32.1.22:8090/recommended"); 
 String result = this.restTemplate.getForObject(uri, String.class); 
 return result; 
}

public String recommendFallback() { 
 return "No recommend available"; 
} 
@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback", 
commandProperties = { 
 @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500") 
}) 
public String anyMethodWithExternalDependency1() {
 URI uri = URI.create("http://172.32.1.22:8090/recommended"); 
 String result = this.restTemplate.getForObject(uri, String.class); 
 return result; 
}

public String recommendFallback() { 
 return "No recommend available"; 
} 

출처: https://netflixtechblog.com/fault-tolerance-in-a-high-volume-distributed-system-91ab4faae74a