Resilience4j etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Resilience4j etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

9 Mayıs 2023 Salı

Resilience4j @CircuitBreaker Anotasyonu applicaiton.properties

Örnek
Şöyle yaparız
resilience4j.circuitbreaker.instances.default.failure-rate-threshold=60
Örnek
Şöyle yaparız
management:
  health:
    circuitbreakers:
      enabled: true
  endpoints:
    web:
      exposure:
        include: health
  endpoint:
    health:
      show-details: always
resilience4j:
  circuitbreaker:
    instances:
      callerService:
        registerHealthIndicator: true
        eventConsumerBufferSize: 10
        failureRateThreshold: 10
        minimumNumberOfCalls: 5
        automaticTransitionFromOpenToHalfOpenEnabled: true
        waitDurationInOpenState: 5s
        permittedNumberOfCallsInHalfOpenState: 3
        slidingWindowSize: 10
        slidingWindowType: COUNT_BASED
Açıklaması şöyle
- registerHealthIndicator: true: This line is telling the service to register a health indicator, which can be used to monitor the overall health of the service.

- eventConsumerBufferSize: 10: This is the size of the buffer that will store events from the Circuit Breaker.

- failureRateThreshold: 10: This is the threshold for the failure rate of calls. If the failure rate of calls exceeds this threshold, the Circuit Breaker will trip.

- minimumNumberOfCalls: 5: This is the minimum number of calls that the Circuit Breaker will monitor before it starts tripping.

- automaticTransitionFromOpenToHalfOpenEnabled: true: This line enables automatic transition from the open state to the half-open state after the wait duration has elapsed.

- waitDurationInOpenState: 5s: This is the duration that the Circuit Breaker will wait in the open state before attempting to automatically transition to the half-open state.

- permittedNumberOfCallsInHalfOpenState: 3: This is the maximum number of calls that the Circuit Breaker will allow in the half-open state.

- slidingWindowSize: 10: This is the size of the sliding window that the Circuit Breaker will use to monitor calls.

slidingWindowType: COUNT_BASED: This line specifies the type of sliding window that the Circuit Breaker will use, which in this case is a count-based sliding window. There are other options for slidingWindowType like TIME_BASED, TIME_BASED_RESET etc which can be used for specific use cases.

Örnek
application.properties dosyası şöyledir
resilience4j:
    circuitbreaker:
        instances:
            mockService:
                slidingWindowSize: 3
                slidingWindowType: COUNT_BASED
                #waitDurationInOpenState: 5
                waitInterval: 10000
                failureRateThreshold: 50
                permittedNumberOfCallsInHalfOpenState: 5
                registerHealthIndicator: true
                #register-health-indicator: true
                allowHealthIndicatorToFail: true
        configs:
            default:
                registerHealthIndicator: true

13 Eylül 2021 Pazartesi

Resilience4j @RateLimiter Anotasyonu

Maven
Şu satırı dahil ederiz. @RateLimiter anotasyonu kullanılır
<dependency>
  <groupId>io.github.resilience4j</groupId>
  <artifactId>resilience4j-spring-boot2</artifactId>
  <version>1.7.1</version>
</dependency>
Örnek
Elimizde şöyle bir dosya olsun
resilience4j.ratelimiter.instances.default.limit-for-period=100
resilience4j.ratelimiter.instances.default.limit-refresh-period=5s
Şöyle yaparız
@GetMapping("ms1")
@RateLimiter(name="default")
public String callingMS2() {
  return "MS1 can handle only 100 requests per 5 seconds");
}
Örnek
Elimizde şöyle bir dosya olsun. Burada stockService için 5 saniyede bir istek kabul edileceği belirtiliyor.
resilience4j.ratelimiter:
  instances:
    stockService:
      limitForPeriod: 1
      limitRefreshPeriod: 5s
      timeoutDuration: 0s
Açıklaması şöyle
limitRereshPeriod is the interval — in our case it is 5 seconds
limitForPeriod is number of requests to make every 5 seconds. In our case, it should be just 1. We want to make only one call every 5 second. All other requests should not be allowed within the 5 second window
timeoutDuration — additional requests within the 5 seconds should be timedout immediately.
Şöyle yaparız
import io.github.resilience4j.ratelimiter.annotation.RateLimiter; @Service
public class StockService {

  @RateLimiter(name="stockService", fallbackMethod = "getFallbackStocks")
  public List<StockPrice> getStocks() {
    ...
  }

  public List<StockPrice> getFallbackStocks(Exception e) {
    return ...;
  }
}