【问题标题】:How to decorate a consumer functional interface with retry in resilience4j如何在resilience4j中通过重试来装饰消费者功能界面
【发布时间】:2020-08-23 22:44:47
【问题描述】:

目前resilience4j-all库中的DecorateConsumer.java没有提供Retry的装饰方法(仅支持Circuit Breaker、RateLimiter和BulkHead)。

Retry.java 类也没有提供这个选项

我有一个消费者函数 public void call(String key),它在内部使用 key 的值执行休息调用。

但弹性 4j 文档提到“您可以通过重试来装饰任何 Callable、Supplier、Runnable、Consumer、CheckedRunnable、CheckedSupplier、CheckedConsumer 或 CompletionStage。”

我们如何在resilience4j 中使用Retry 来装饰消费者功能接口

【问题讨论】:

    标签: resilience4j


    【解决方案1】:

    你可以的

    String key = "key";
    Runnable runnable = () -> helloWorldService.sayHelloWorldWithName(key);
    Decorators
        .ofRunnable(runnable)
        .withRetry(Retry.ofDefaults("id"))
        .run();
    

    或者只是

    Runnable runnable = () -> helloWorldService.sayHelloWorldWithName(key);
    retry.executeRunnable(runnable);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-08
      • 2022-01-09
      • 2021-11-24
      • 2021-05-09
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      相关资源
      最近更新 更多