content: /**
   * Copyright (c) 2010-present Abixen Systems. All rights reserved.
   * <p>
   * This library is free software; you can redistribute it and/or modify it under
   * the terms of the GNU Lesser General Public License as published by the Free
   * Software Foundation; either version 2.1 of the License, or (at your option)
   * any later version.
   * <p>
   * This library is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
   * details.
   */
  
  package com.abixen.platform.gateway.configuration;
  
  
  import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
  import io.github.resilience4j.timelimiter.TimeLimiterConfig;
  import org.springframework.cloud.circuitbreaker.resilience4j.ReactiveResilience4JCircuitBreakerFactory;
  import org.springframework.cloud.client.circuitbreaker.Customizer;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JConfigBuilder;
  
  import java.time.Duration;
  
  
  @Configuration
  public class PlatformCircuitBreakerConfiguration {
  
      private static final Duration TIMEOUT_DURATION = Duration.ofMillis(200);
      private static final int SLIDING_WINDOW_SIZE = 10;
      private static final float FAILURE_RATE_THRESHOLD = 50;
  
      @Bean
      public Customizer<ReactiveResilience4JCircuitBreakerFactory> defaultCustomizer() {
          return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
                  .circuitBreakerConfig(CircuitBreakerConfig.custom()
                          .slidingWindowSize(SLIDING_WINDOW_SIZE)
                          .failureRateThreshold(FAILURE_RATE_THRESHOLD)
                          .build())
                  .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(TIMEOUT_DURATION).build())
                  .build());
      }
  
  }