Преглед на файлове

scg, resilience4j 구성

hyojungkim преди 5 години
родител
ревизия
8df2ef92b5

+ 3 - 10
apigateway/bin/main/application.yml

@@ -3,8 +3,9 @@ server:
 
 eureka:
   client:
-    service-url:
-      defaultZone: http://${EUREKA}/eureka
+    register-with-eureka: false
+    serviceUrl:
+      defaultZone: ${EUREKA}
     healthcheck:
       enabled: true
 
@@ -15,19 +16,11 @@ spring:
     loadbalancer:
       ribbon:
         enabled: false
-      retry:
-        enabled: true
     gateway:
       discovery:
         locator:
           enabled: true
       default-filters:
-      - name: Retry
-        args:
-          retries: 3
-          series:
-          methods: "GET"
-          exception: "java.net.ConnectException"
       - name: CircuitBreaker
         args:
           name: fetchIngredients

BIN
apigateway/bin/main/com/idatabank/scg/apigateway/FallbackController.class


BIN
apigateway/bin/main/com/idatabank/scg/apigateway/Resilience4jConfig.class


+ 4 - 4
apigateway/build.gradle

@@ -17,17 +17,17 @@ ext {
 }
 
 dependencies {
+	implementation 'org.springframework.boot:spring-boot-starter-actuator'
 	implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
 	developmentOnly 'org.springframework.boot:spring-boot-devtools'
 	implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
-	implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix'
-  implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
 	implementation 'org.springframework.boot:spring-boot-starter'
-  implementation 'org.springframework.boot:spring-boot-starter-actuator'
+	implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix'
+	implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
+
 	testImplementation('org.springframework.boot:spring-boot-starter-test') {
 		exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
 	}
-	compile group: 'org.springframework.retry', name: 'spring-retry', version: '1.2.5.RELEASE'
 }
 
 dependencyManagement {

+ 1 - 1
apigateway/src/main/java/com/idatabank/scg/apigateway/FallbackController.java

@@ -17,6 +17,6 @@ public class FallbackController {
   public Mono<String> fallback(ServerWebExchange exchange) {
     Throwable exception = exchange.getAttribute(ServerWebExchangeUtils.CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR);
     logger.debug("", exception);
-    return Mono.just("fallback-gateway");
+    return Mono.just("fallback-gateway => " + exception.toString());
   }
 }

+ 5 - 3
apigateway/src/main/java/com/idatabank/scg/apigateway/Resilience4jConfig.java

@@ -14,9 +14,11 @@ public class Resilience4jConfig {
 
   @Bean
   public Customizer<ReactiveResilience4JCircuitBreakerFactory> defaultCustomizer() {
-    CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom().failureRateThreshold(50)
-        .permittedNumberOfCallsInHalfOpenState(30).slidingWindowSize(20).minimumNumberOfCalls(5)
-        .waitDurationInOpenState(Duration.ofMillis(5000)).build();
+    CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom().failureRateThreshold(20) //
+        .permittedNumberOfCallsInHalfOpenState(5) // half open 상태일 때 요청 수
+        .slidingWindowSize(100) //
+        .minimumNumberOfCalls(10) //
+        .waitDurationInOpenState(Duration.ofMillis(20000)).build(); // circuit open 상태를 얼마나 지속할지 설정
     return factory -> factory
         .configureDefault(id -> new Resilience4JConfigBuilder(id).circuitBreakerConfig(circuitBreakerConfig).build());
   }

+ 3 - 10
apigateway/src/main/resources/application.yml

@@ -3,8 +3,9 @@ server:
 
 eureka:
   client:
-    service-url:
-      defaultZone: http://${EUREKA}/eureka
+    register-with-eureka: false
+    serviceUrl:
+      defaultZone: ${EUREKA}
     healthcheck:
       enabled: true
 
@@ -15,19 +16,11 @@ spring:
     loadbalancer:
       ribbon:
         enabled: false
-      retry:
-        enabled: true
     gateway:
       discovery:
         locator:
           enabled: true
       default-filters:
-      - name: Retry
-        args:
-          retries: 3
-          series:
-          methods: "GET"
-          exception: "java.net.ConnectException"
       - name: CircuitBreaker
         args:
           name: fetchIngredients

+ 2 - 2
eurekaserver/bin/main/application.yml

@@ -3,8 +3,8 @@ spring:
     name: eureka-server
 eureka:
   client:
-    register-with-eureka: false  #유레카에 클라이언트로 등록할지 여부
-    fetch-registry: false  #유레카 서버에서 서비스 목록을 가져올지 여부
+    serviceUrl:
+      defaultZone: ${EUREKA}
 server:
   port: 8761
 

+ 2 - 1
eurekaserver/bin/main/application_.properties

@@ -1,5 +1,6 @@
 spring.application.name=eureka-server
-eureka.client.serviceUrl.defaultZone=http://${EUREKA}/eureka/
+# eureka.client.serviceUrl.defaultZone=http://${EUREKA}/eureka/
+eureka.client.serviceUrl.defaultZone=${EUREKA}
 server.port=8761
 eureka.client.register-with-eureka=true
 eureka.client.fetch-registry=true

+ 2 - 2
eurekaserver/src/main/resources/application.yml

@@ -3,8 +3,8 @@ spring:
     name: eureka-server
 eureka:
   client:
-    register-with-eureka: false  #유레카에 클라이언트로 등록할지 여부
-    fetch-registry: false  #유레카 서버에서 서비스 목록을 가져올지 여부
+    serviceUrl:
+      defaultZone: ${EUREKA}
 server:
   port: 8761
 

+ 2 - 1
eurekaserver/src/main/resources/application_.properties

@@ -1,5 +1,6 @@
 spring.application.name=eureka-server
-eureka.client.serviceUrl.defaultZone=http://${EUREKA}/eureka/
+# eureka.client.serviceUrl.defaultZone=http://${EUREKA}/eureka/
+eureka.client.serviceUrl.defaultZone=${EUREKA}
 server.port=8761
 eureka.client.register-with-eureka=true
 eureka.client.fetch-registry=true