概述
package com.example.demo; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/app") public class AppController { @RequestMapping("/get/{id}") @HystrixCommand(fallbackMethod = "getFallBack", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500") }) public String get(@PathVariable("id") long id) throws Exception { // throw new Exception("error"); Thread.sleep(id); return "get"; } public String getFallBack(@PathVariable("id") long id) { return "getFallBack"; } }
package com.example.demo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/app")
public class AppController {
@RequestMapping("/get/{id}")
@HystrixCommand(fallbackMethod = "getFallBack", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
})
public String get(@PathVariable("id") long id) throws Exception {
// throw new Exception("error");
Thread.sleep(id);
return "get";
}
public String getFallBack(@PathVariable("id") long id) {
return "getFallBack";
}
}
转载于:https://www.cnblogs.com/tiancai/p/9578461.html
最后
以上就是追寻发箍为你收集整理的Hystrix的用法的全部内容,希望文章能够帮你解决Hystrix的用法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复