美文网首页
Soul源码阅读 hystrix【第十八天】

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

作者: cutieagain | 来源:发表于2021-02-05 01:22 被阅读0次

首先,看一下熔断插件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"
}

相关文章

网友评论

      本文标题:Soul源码阅读 hystrix【第十八天】

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