我可以使用hystrix再次调用失败的请求吗?

问题描述 投票:-1回答:1

我有一个假客户端,每60秒将一个请求发送到另一个微服务。在此控制器上,我将HystrixCommand批注与用户配置一起使用(只是进行实验)。我也有一个后备方法,当请求失败时,我会进入该方法。但是,预期的数据对我来说非常敏感,因此从后备方法发送空数据毫无意义。

问题:如何以任意间隔再次执行失败的请求2-3次? Hystrix是否具有此功能?

我有一个想法,可以使用fallback方法再次调用该请求,并将已执行请求的数量保存在某个位置,每次将它们与limit-variable进行比较,但我不喜欢它。

 @HystrixCommand(
            threadPoolKey = "currencyThreadPool",
            threadPoolProperties = {
                    @HystrixProperty(name = "coreSize", value = "30"),
                    @HystrixProperty(name = "maxQueueSize", value = "10")},
            commandProperties = {
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
                    @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "90"),
                    @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),
                    @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "15000"),
                    @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "5")}
    )
spring-boot hystrix feign
1个回答
0
投票

最后,我使用了Spring Retry库,它完全满足了我的要求。

@Retryable(value = {ConnectException.class, FeignException.class}, maxAttempts = 4,
        backoff = @Backoff(delay = 5000, maxDelay = 80000, multiplier = 4))
© www.soinside.com 2019 - 2024. All rights reserved.