(57)Part14-Sentinel服务容错-05-OpenFeign整合Sentinel

1、开启Sentinel支持

在edu的yml配置文件中开启Feign对Sentinel的支持

feign:
  sentinel:
    enabled: true

2、创建容错类

package com.atguigu.guli.service.edu.feign.fallback;

@Service
@Slf4j
public class OssFileServiceFallBack implements OssFileService {

    @Override
    public R test() {
        return R.error();
    }

    @Override
    public R removeFile(String url) {
        log.warn("熔断保护");
        return R.error();
    }
}

4、指定容错类

为OpenFeign远程调用接口添加fallback属性值没指定容错类

@Service
@FeignClient(value = "service-oss", fallback = OssFileServiceFallBack.class)
public interface OssFileService {

5、测试

停止oss微服务,测试删除讲师的功能

你可能感兴趣的:(在线教育)