-->
当前位置:首页 > articles > 正文内容

Luz1个月前 (10-28)articles261

CircuitBreaker will not open R4J

  • catfish 问题:
    •  @Serviceclass CatGateway {    val logger = LoggerFactory.getLogger(CatGateway::class.java)    @Value("\${catservice.baseurl}")    lateinit var baseUrl: String    val GET_ENDPOINT = "/cat"    val restClient = RestTemplate();    @CircuitBreaker(name = "catGateway", fallbackMethod = "dogFallback")    fun getCatById(id: Int): Cat?{        val result = restClient.getForObject("$baseUrl/$GET_ENDPOINT/$id", ByteArray::class.java)        return jacksonObjectMapper().readValue(result, Cat::class.java )    }    fun dogFallback(t: Throwable): Cat?{        logger.error("Circuitbreaker opened")        throw CatNotFoundException("Cat not found, cause service broke");    }}data class Cat(val id: Int) 
    • catservice:  baseurl: "http://localhost:8080/api"server:  port: 8085resilience4j:  circuitbreaker:    configs:      shared:        register-health-indicator: true        sliding-window-type: count_based        sliding-window-size: 5        failure-rate-threshold: 40        permitted-number-of-calls-in-half-open-state: 1        max-wait-duration-in-half-open-state: 10s        wait-duration-in-open-state: 10s        slow-call-duration-threshold: 2s        writable-stack-trace-enabled: true        automatic-transition-from-open-to-half-open-enabled: true    instances:      catGateway:        base-config: sharedmanagement:  health:    circuitbreakers:      enabled: true  endpoint:    health:      show-details: always
    •         <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-actuator</artifactId>            <version>2.7.5</version>        </dependency>
  • 回答:
返回列表

上一篇:

下一篇:

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。