- @RestController
- public class UserController {
- protected final Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- UserServiceClient userServiceClient;
- /**
- * 根據用戶id獲取電話號碼
- * @param userId
- * @return 電話號碼
- *
- * 調用例子:http://localhost:12345/getPhoneNoByUserId?userId=263508
- */
- @RequestMapping(value = "/getPhoneNoByUserId", method = RequestMethod.GET)
- public String getPhoneNoByUserId(@RequestParam Integer userId) {
- logger.debug("getPhoneNoByUserId received. userId={}", userId);
- return userServiceClient.getPhoneNoByUserId(userId);
- }
- }
- /**
- * 調用user微服務的客戶端接口
- * @author XuJijun
- *
- */
- //@FeignClient(value="user-service", fallback=UserServiceClientHystrix.class)
- @FeignClient(value="user-service")
- public interface UserServiceClient {
- /**
- * 根據userId獲取電話號碼
- */
- @RequestMapping(value = "/user/getPhoneNoByUserId", method = RequestMethod.GET)
- public String getPhoneNoByUserId(@RequestParam(value = "userId") Integer userId);
- }
- hystrix:
- command:
- default:
- execution:
- isolation:
- thread:
- timeoutInMilliseconds: 30000 #缺省爲1000
- hystrix:
- threadpool:
- default:
- coreSize: 500 #缺省爲10
- 超時時間(默認1000ms,單位:ms)
- hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
- hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds
- 線程池核心線程數
- hystrix.threadpool.default.coreSize(默認爲10)
- Queue
- hystrix.threadpool.default.maxQueueSize(最大排隊長度。默認-1,使用SynchronousQueue。其他值則使用 LinkedBlockingQueue。如果要從-1換成其他值則需重啓,即該值不能動態調整,若要動態調整,需要使用到下邊這個配置)
- hystrix.threadpool.default.queueSizeRejectionThreshold(排隊線程數量閾值,默認爲5,達到時拒絕,如果配置了該選項,隊列的大小是該隊列)
- 注意:如果maxQueueSize=-1的話,則該選項不起作用
- 斷路器
- hystrix.command.default.circuitBreaker.requestVolumeThreshold(當在配置時間窗口內達到此數量的失敗後,進行短路。默認20個)
- hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds(短路多久以後開始嘗試是否恢復,默認5s)
- hystrix.command.default.circuitBreaker.errorThresholdPercentage(出錯百分比閾值,當達到此閾值後,開始短路。默認50%)
- fallback
- hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests(調用線程允許請求HystrixCommand.GetFallback()的最大數量,默認10。超出時將會有異常拋出,注意:該項配置對於THREAD隔離模式也起作用)
轉載地址:http://blog.csdn.net/clementad/article/details/54315805