<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Resilience4j輕量級(jí)的容錯(cuò)組件

          聯(lián)合創(chuàng)作 · 2023-09-28 11:37

          Resilience4j 是一個(gè)輕量級(jí)的容錯(cuò)組件,其靈感來(lái)自于 Hystrix,但主要為 Java 8 和函數(shù)式編程所設(shè)計(jì)。輕量級(jí)體現(xiàn)在其只用 Vavr 庫(kù)(前身是 Javaslang),沒(méi)有任何外部依賴(lài)。而 Hystrix 依賴(lài)了 Archaius ,Archaius 本身又依賴(lài)很多第三方包,例如 Guava、Apache Commons Configuration 等。

          限速組件架構(gòu):

          Resilience4j 提供了如下幾款核心組件

          • resilience4j-circuitbreaker: Circuit breaking

          • resilience4j-ratelimiter: Rate limiting

          • resilience4j-bulkhead: Bulkheading

          • resilience4j-retry: Automatic retrying (sync and async)

          • resilience4j-cache: Response caching

          附件組件包括:

          • resilience4j-reactor: Spring Reactor adapter

          • resilience4j-rxjava2: RxJava2 adapter

          • resilience4j-micrometer: Micrometer Metrics exporter

          • resilience4j-metrics: Dropwizard Metrics exporter

          • resilience4j-prometheus: Prometheus Metrics exporter

          • resilience4j-spring-boot: Spring Boot Starter

          • resilience4j-ratpack: Ratpack Starter

          • resilience4j-retrofit: Retrofit Call Adapter Factories

          • resilience4j-vertx: Vertx Future decorator

          • resilience4j-consumer: Circular Buffer Event consumer

          使用示例:

          使用 Resilience4j 實(shí)現(xiàn)請(qǐng)求調(diào)用頻率限制的示例代碼:

          // Create a custom RateLimiter configuration
          RateLimiterConfig config = RateLimiterConfig.custom()
              .timeoutDuration(Duration.ofMillis(100))
              .limitRefreshPeriod(Duration.ofSeconds(1))
              .limitForPeriod(1)
              .build();
          // Create a RateLimiter
          RateLimiter rateLimiter = RateLimiter.of("backendName", config);
          
          // Decorate your call to BackendService.doSomething()
          Supplier<String> restrictedSupplier = RateLimiter
              .decorateSupplier(rateLimiter, backendService::doSomething);
          
          // First call is successful
          Try<String> firstTry = Try.ofSupplier(restrictedSupplier);
          assertThat(firstTry.isSuccess()).isTrue();
          
          // Second call fails, because the call was not permitted
          Try<String> secondTry = Try.of(restrictedSupplier);
          assertThat(secondTry.isFailure()).isTrue();
          assertThat(secondTry.getCause()).isInstanceOf(RequestNotPermitted.class);
          瀏覽 29
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  人人看人人爱人人搞 | 国产成人无码精免费视频 | w w w大香蕉 | 一级婬片试看15分钟免费 | 五月色 亚洲 |