Spring Cloud Netflix—如何加入Hystrix

要在项目中包含Hystrix,请使用组org.springframework.cloud和artifact id spring-cloud-starter-hystrix的启动器。有关 使用当前的Spring Cloud发布列表设置构建系统的详细信息,请参阅Spring Cloud项目页面。 示例启动应用程序:

@SpringBootApplication @EnableCircuitBreaker public class Application {

public static void main(String[] args) {
    new SpringApplicationBuilder(Application.class).web(true).run(args);
}
复制代码

}

@Component public class StoreIntegration {

@HystrixCommand(fallbackMethod = "defaultStores")
public Object getStores(Map<String, Object> parameters) {
    //do stuff that might fail
}

public Object defaultStores(Map<String, Object> parameters) {
    return /* something useful */;
}
复制代码

} @HystrixCommand由名为“javanica”的Netflix contrib库提供 。Spring Cloud在连接到Hystrix断路器的代理中使用该注释自动包装Spring bean。断路器计算何时打开和关闭电路,以及在发生故障时应该做什么。

要配置@HystrixCommand,您可以使用commandProperties属性列出@HystrixProperty注释。请参阅 这里 了解更多详情。有关 可用属性的详细信息,请参阅Hystrix维基。

源码来源:http://minglisoft.cn/honghu/technology.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值