Spring Cloud Netflix—如何加入Hystrix

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

@SpringBootApplication @EnableCircuitBreaker public class Application {java

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

}web

@Component public class StoreIntegration {spring

@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。断路器计算什么时候打开和关闭电路,以及在发生故障时应该作什么。ui

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

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

相关文章
相关标签/搜索