美文网首页
Spring Cloud Netflix—如何加入Hystrix

Spring Cloud Netflix—如何加入Hystrix

作者: 万万558 | 来源:发表于2018-03-05 15:03 被阅读0次

要在项目中包含Hystrix,请使用组org.springframework.cloud和artifact idspring-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 parameters) {

        //do stuff that might fail

    }

    public Object defaultStores(Map parameters) {

        return /* something useful */;

    }

}

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

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

源码来源

相关文章

网友评论

      本文标题:Spring Cloud Netflix—如何加入Hystrix

      本文链接:https://www.haomeiwen.com/subject/jljhfftx.html