一 说明
1.1 说明
本案例改用openfegin进行模块间进行通信。
1.2 架构图
二 实施操作
2.1 配置操作
1.pom文件
<!--SpringCloud openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.配置文件
3.启动类
4.调用service
/**
* @auther zzyy
* @create 2020-02-25 18:15
*/
@FeignClient(value = "mscloud-alibaba-nacos-provider",fallback = PaymentFallbackService.class)
public interface PaymentService
{
@GetMapping(value = "/payment/get/{id}")
public CommonResult<Payment> paymentMoney(@PathVariable("id") Long id);
}
@Component
public class PaymentFallbackService implements PaymentService
{
@Override
public CommonResult<Payment> paymentMoney(Long id) {
return new CommonResult<>(44444,"服务降级返回,---PaymentFallbackService",new Payment(id,"errorSerial"));
}
}
controller调用
2.2 测试操作
2.2.1 启动配置
1.启动nacos,sentinel
2.启动应用程序
3.设置sentinel的限流规则
2.2.2 测试
1.访问接口
快速访问,触发限流规则
2.触发降级规则
将提供者6001,6002 关闭,查看6000会触发降级规则
查看到此时已经触发降级规则显示。