服务提供者【test-provider8001】
Openfeign远程调用服务提供者搭建
文章地址http://t.csdnimg.cn/06iz8
相关接口
测试远程调用:http://localhost:8001/payment/index
服务消费者【test-consumer-resilience4j8004】
Openfeign远程调用消费者搭建
文章地址http://t.csdnimg.cn/06iz8
依赖
 <!-- resilience4j  -->
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-spring-cloud2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
        </dependency> 
application.yml
resilience4j:
  # 重试机制,此处backendA是自己定义的名称,对应@Retry的name
  retry:
    instances:
      # 实例名称:自己定义的名称,对应@TimeLimiter中的name
      backendA:
        # 最大重试次数
        maxRetryAttempts: 3
        # 固定的重试间隔,10中之内重试三次
        waitDuration: 10s
        # 表示是否开启指数退避抖动算法
        enableExponentialBackoff: true
        # 表示时间间隔乘数
        exponentialBackoffMultiplier: 2 
OrderController【控制层】
/**
     * 测试重试机制
     *
     * @return
     */
    @GetMapping("/retry")
    @Retry(name = "backendA")
    //重试机制注解【会按照配置重试此接口】:name:对应application.yml的重试机制配置名称
    public CompletableFuture<String> retry() {
        log.info("********* 进入方法 ******");
        //resilience4j一般用异步操作,此处使用lambda表达式
        CompletableFuture<String> completableFuture = CompletableFuture
                .supplyAsync((Supplier<String>) () -> (paymentFeignService.paymentIndex()));
        log.info("********* 离开方法 ******");
        return completableFuture;
    } 
相关接口
测试重试机制:
http://localhost:8004/order/retry



















