- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个通过 REST 调用依赖项的服务。服务和依赖是微服务架构的一部分,所以我想使用弹性模式。我的目标是:
TimeLimiter
和
Bulkhead
类,因为它们似乎可以协同工作。
@Component
class FooService(@Autowired val circuitBreakerRegistry: CircuitBreakerRegistry)
{
...
// State machine to take load off the dependency when slow or unresponsive
private val circuitBreaker = circuitBreakerRegistry
.circuitBreaker("fooService")
// Limit parallel requests to dependency
private var semaphore = Semaphore(maxParallelRequests)
// The protected function
private suspend fun makeHttpCall(customerId: String): Boolean {
val client = webClientProvider.getCachedWebClient(baseUrl)
val response = client
.head()
.uri("/the/request/url")
.awaitExchange()
return when (val status = response.rawStatusCode()) {
200 -> true
204 -> false
else -> throw Exception(
"Foo service responded with invalid status code: $status"
)
}
}
// Main function
suspend fun isFoo(someId: String): Boolean {
try {
return circuitBreaker.executeSuspendFunction {
semaphore.withPermit {
try {
withTimeout(timeoutMs) {
makeHttpCall(someId)
}
} catch (e: TimeoutCancellationException) {
// This exception has to be converted because
// the circuit-breaker ignores CancellationException
throw Exception("Call to foo service timed out")
}
}
}
} catch (e: CallNotPermittedException) {
logger.error { "Call to foo blocked by circuit breaker" }
} catch (e: Exception) {
logger.error { "Exception while calling foo service: ${e.message}" }
}
// Fallback
return true
}
}
// Main function
suspend fun isFoo(someId: String): Boolean {
return monoOf(makeHttpCall(someId))
.bulkhead(bulkhead)
.timeLimiter(timeLimiter)
.circuitBreaker(circuitBreaker)
}
最佳答案
您也可以使用 Resilience4j 的 Bulkhead 而不是您自己的 Semaphore 和 Resilience4j 的 TimeLimiter。
您可以使用 bulkhead.executeSuspendFunction
堆叠断路器和 timelimiter.executeSuspendFunction
.
关于spring-boot - 如何将 CircuitBreaker 与 TimeLimiter 和 Bulkhead 结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62202344/
我有一个带有 Jubilee 的 Spring Boot 2.6.0-M1 项目(但问题可以从 2.4 开始重现)。在我的项目中,我使用了 Actuator、Spring cloud Kubernet
我遇到了@CircuitBreaker 没有重试的问题。 我有一个服务类(例如 UserService 类和方法名称 getUser),此方法调用另一个 Spring bean(例如 AppClien
是否可以监控所有Circuit Breakers限制和大小? Fielddata Breaker可以通过节点使用它来监控: GET _nodes/stats/breaker,http 但是我们如何监控
我有一个 spring boot 应用程序,它迭代地调用 mockserver通过 hystrix 命令实例化,带有回退方法。 模拟服务器被配置为始终以状态代码 500 响应。当在没有 circuit
我们正在使用响应式(Reactive)伪装客户端 (com.playtika.reactivefeign:feign-reactor-spring-cloud-starter:3.2.0) 断路器版本
我尝试将重试策略与带有 Failsafe 的 CircuitBreaker 模式结合起来,但当尝试打开电路并中断时,我收到了 CircuitBreakerOpenException 异常。 https
CircuitBreaker CircuitBreaker主要分为以下几个模块:熔断器配置,熔断器注册,熔断事件消费者注册,熔断器状态机,熔断器状态及指标,熔断器事件,熔断器事件处理器,熔断器
我在 Gradle 中使用 Spring Boot 2.4。 这是我定义依赖项的方式: compile 'org.springframework.cloud:spring-cloud-starter-
我正在尝试为我的 Rest 客户创建一个综合弹性策略,为此我编写了以下内容: private static Policy circuitBreakerPolicy = Policy .Han
我正在尝试使用 Resilience4j 的 Spring Boot 注释。 当我使用注释时@CircuitBreaker(name = BACKEND,fallbackMethod = "fallb
尽管对于其他返回类型,Spring 重试回退机制似乎工作正常,但是当涉及到调用返回类型为 void 的 API 时。恢复方法根本没有被调用,我已经尝试了所有可能的方法参数类型并更改了后备方法的返回类型
Spring 的@Retryable 注释将重试三次(默认)并回退到@Recovery 方法。然而,@CircuitBreaker 将重试一次并在状态关闭时回退。 我想结合这两者:当断路器状态为关闭时
现在我在 hystrix 中使用 feign,结果发现,当 fallback 方法在 5 秒内调用 20 次时,Circuit 将变为 Open 状态。我怎样才能改变这个规则。例如,当fallback
我有一个通过 REST 调用依赖项的服务。服务和依赖是微服务架构的一部分,所以我想使用弹性模式。我的目标是: 有一个断路器来保护它挣扎时的依赖 限制调用可以运行的时间。该服务具有 SLA,并且必须在特
我正在使用 spring boot 1.3.1 和 spring cloudl Brixtom.M4,在使用 springboot 1.3.1 时我发现 Turbine-AMQP 项目不再可用,我们现
我是一名优秀的程序员,十分优秀!