Soul源碼閱讀 hystrix【第十八天】

首先,看一下熔斷插件hystrix的介紹 netflix hystrix插件介紹
簡而言之,作用就是,復(fù)雜分布式體系結(jié)構(gòu)中的應(yīng)用程序具有數(shù)十種依賴關(guān)系,每種依賴關(guān)系不可避免地會在某個時刻失敗。如果主機(jī)應(yīng)用程序未與這些外部故障隔離開來,可能會導(dǎo)致大部分請求無效,這個時候就需要熔斷插件。

Soul啟用hystrix插件

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

插件管理中開啟使用


image.png

維護(hù)選擇器


image.png

維護(hù)規(guī)則


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;
    }

返回結(jié)果

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

soul-examples-http 啟動一個8189端口的測試,可以在指定時間內(nèi)返回的,請求成功,返回

{
    "id": "1",
    "name": "hello world findById"
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容