Soul源码阅读 hystrix【第十八天】

首先,看一下熔断插件hystrix的介绍 netflix hystrix插件介绍
简而言之,作用就是,复杂分布式体系结构中的应用程序具有数十种依赖关系,每种依赖关系不可避免地会在某个时刻失败。如果主机应用程序未与这些外部故障隔离开来,可能会导致大部分请求无效,这个时候就需要熔断插件。

Soul启用hystrix插件

<dependency>
      <groupId>org.dromara</groupId>
      <artifactId>soul-spring-boot-starter-plugin-hystrix</artifactId>
       <version>${last.version}</version>
  </dependency>

插件管理中开启使用


image.png

维护选择器


image.png

维护规则


image.png

soul-examples-http 启动一个8188端口的测试

server:
  port: 8188
  address: 0.0.0.0


soul:
  http:
    adminUrl: http://localhost:9095
    port: 8188
    contextPath: /http
    appName: http
    full: fals
@GetMapping("/findById")
    @SoulSpringMvcClient(path = "/findById", desc = "Find by id")
    public OrderDTO findById(@RequestParam("id") final String id) {
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setId(id);
        orderDTO.setName("hello world findById");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return orderDTO;
    }

返回结果

{
    "code": -104,
    "message": "Service call timeout!",
    "data": null
}

soul-examples-http 启动一个8189端口的测试,可以在指定时间内返回的,请求成功,返回

{
    "id": "1",
    "name": "hello world findById"
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容