一、sentinel控制台的使用
1、sentinel控制台jar包地址:
Releases · alibaba/Sentinel · GitHub
账号密码都为sentinel
控制台访问地址:http://localhost:8080
2、sentinel的maven坐标
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2021.1</version>
</dependency>
3、配置
spring:
cloud:
sentinel:
transport:
dashboard: localhost:8080
4、显示结果
访问http://localhost:8080进入控制台
二、sentinel整合feign的使用与步骤
1、yml文件进行开启
feign:
sentinel:
enabled: true
2、给FeignClient编写FallBackFactory并注册为bean
编写FallBackFactory(调用哪个Feign编写哪个)
@Component
public class ProductFeignFallbackFactory implements FallbackFactory<ProductFeign> {
@Override
public ProductFeign create(Throwable throwable) {
return new ProductFeign() {
@Override
public R test() {
System.out.println("熔断。。。。失败。。。");
return R.failed("失败");
}
};
}
}
注册为bean
public class FeignConfig {
@Bean
public ProductFeignFallbackFactory productFeignFallbackFactory(){
return new ProductFeignFallbackFactory();
}
}
3、将FallbackFactory配置到FeignClient(添加fallbackFactory=所配置的类)
@FeignClient(value = "shop-product",fallbackFactory = ProductFeignFallbackFactory.class)
public interface ProductFeign {
@GetMapping("/shop/product/test")
@ResponseBody
public R test();
}