개별 회로 차단기를 사용자 정의하여 호출별 타임아웃 설정

This commit is contained in:
assu10
2020-11-01 23:55:14 +09:00
parent 0e73c70005
commit 640ffc67f4
3 changed files with 30 additions and 7 deletions

View File

@@ -51,9 +51,18 @@ public class EventController {
*/
@GetMapping(value = "gift/{name}")
public String gift(@PathVariable("name") String gift) {
sleep();
return "[EVENT] Gift is " + gift;
}
private void sleep() {
try {
Thread.sleep(7000); // 7,000 ms (7초), 기본적으로 히스트릭스는 1초 후에 호출을 타임아웃함
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/**
* 레디스 캐싱 데이터 사용
*/

View File

@@ -6,6 +6,7 @@ import com.assu.cloud.memberservice.event.source.SimpleSourceBean;
import com.assu.cloud.memberservice.model.Member;
import com.assu.cloud.memberservice.utils.CustomContextHolder;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.apache.tomcat.util.descriptor.web.ContextHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,7 +96,7 @@ public class MemberController {
}
/**
* Hystrix 테스트 (RestTemplate 를 이용하여 이벤트 서비스의 REST API 호출)
* Hystrix 기본 테스트 (RestTemplate 를 이용하여 이벤트 서비스의 REST API 호출)
*/
@HystrixCommand // 모두 기본값으로 셋팅한다는 의미
@GetMapping(value = "hys/{name}")
@@ -106,6 +107,19 @@ public class MemberController {
return "[MEMBER] " + eventRestTemplateClient.gift(name) + " / port is " + req.getServerPort();
}
/**
* Circuit Breaker 타임아웃 설정 (RestTemplate 를 이용하여 이벤트 서비스의 REST API 호출)
*/
/*@HystrixCommand(
commandProperties = {
@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",
value="5000")}) // 회로차단기의 타임아웃 시간을 5초로 설정*/
@GetMapping(value = "timeout/{name}")
public String timeout(ServletRequest req, @PathVariable("name") String name) {
logger.debug("LicenseService.getLicensesByOrg Correlation id: {}", CustomContextHolder.getContext().getCorrelationId());
return "[MEMBER] " + eventRestTemplateClient.gift(name) + " / port is " + req.getServerPort();
}
/**
* 3번 중 1번은 sleep()
*/
@@ -121,7 +135,7 @@ public class MemberController {
private void sleep() {
try {
Thread.sleep(3000); // 3,000 ms (3초), 기본적으로 히스트릭스는 1초 후에 호출을 타임아웃함
Thread.sleep(7000); // 3,000 ms (3초), 기본적으로 히스트릭스는 1초 후에 호출을 타임아웃함
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@@ -40,14 +40,14 @@ zuul:
sensitive-headers: Cookie,Set-Cookie # 주울이 하위 서비스에 전파하지 않는 헤더 차단 목록 (디폴트는 Cookie, Set-Cookie, Authorization)
hystrix:
command:
default:
default: # 유레카 서비스 ID
execution:
isolation:
thread:
timeoutInMilliseconds: 5000 # 히스트릭스 타임아웃 5초로 설정 (기본 1초)
#event-service:
# ribbon:
# ReadTimeout: 3000 # 리본 타임아웃 3초로 설정 (기본 5초)
timeoutInMilliseconds: 5000 # 히스트릭스 타임아웃 5초로 설정 (기본 1초, ribbon 의 타임아웃보다 커야 기대하는 대로 동작함)
event-service:
ribbon:
ReadTimeout: 5000 # 리본 타임아웃 5초로 설정 (기본 5초)
logging:
level:
com.netflix: WARN