服务降级
一、服务降级所需要的依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>1.7.1</version>
</dependency>
<!-- 在dubbo使用 Sentinel 需要添加下面依赖 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
<version>1.7.1</version>
</dependency>
二、需要降级的service加入注解
@FeignClient(value = "service-credit", fallback = CreditServiceFallback.class)
public interface CreditService {
@GetMapping("/credit/addCredit")
R addCredit();
}
三、写CreditServiceFallback类
@Component
public class CreditServiceFallback implements CreditService {
@Override
public R addCredit() {
System.out.println("fallback的信息");
return R.ok();
}
}