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