Sentinel -【整合OpenFeign降级】
①添加依赖
<!--引入Web依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--nacos服务注册发现-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--openfeign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!--sentinel启动器-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
②启动类加@EnableFeignClients注解开启feign
③开启sentinel对feign的支持
feign.sentinel.enabled=true
④编写openfeign接口,通过fallback属性指定降级处理的类
@FeignClient(value = "FEIGN-B",path = "/b",fallback = GoodsFeignServiceFallback.class)
public interface GoodsFeignService {
@RequestMapping("query")
String query();
}
⑤fallback属性指定的实现类,必须实现原openfeign接口
@Component
public class GoodsFeignServiceFallback implements GoodsFeignService{
public String query() {
return "降级";
}
}