Circuit Breaker
Circuit Breaker مع Resilience4J
10-15 دقيقة
Circuit Breaker مع Resilience4J
يُعدّ نمط Circuit Breaker أساسيًا لإدارة المرونة (Resilience) في معماريات الخدمات المصغّرة. Resilience4J مكتبة خفيفة ووظيفية تطبّق هذا النمط، إضافةً إلى أنماط مرونة أخرى.
1. الإعداد الأساسي
1.1 إضافة الاعتماديات
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot3</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
1.2 إعداد Circuit Breaker
# application.yml
resilience4j:
circuitbreaker:
instances:
productService:
slidingWindowSize: 10
failureRateThreshold: 50
waitDurationInOpenState: 5000
permittedNumberOfCallsInHalfOpenState: 3
eventConsumerBufferSize: 10
ratelimiter:
instances:
productService:
limitForPeriod: 100
limitRefreshPeriod: 1s
timeoutDuration: 0
retry:
instances:
productService:
maxAttempts: 3
waitDuration: 100
enableExponentialBackoff: true
exponentialBackoffMultiplier: 2
exponentialBackoffMaxDuration: 600
retryExceptions:
- org.springframework.web.client.RestClientException
التعليقات
التعليقات مدعومة عبر GitHub Discussions
سجّل الدخول باستخدام GitHub للمشاركة في النقاش