Spring Cloud Gateway中沿着断路器实现重试机制
我想在 Spring Cloud Gateway 中实现重试机制和断路器。目前,当我将断路器过滤器单独添加到 Spring Cloud Gateway 时,它工作正常。如果我单独添加重试过滤器,它也可以正常工作。但我希望在电路更改为打开状态之前自动重试该请求至少 3 次。有什么方法可以集成重试和断路器过滤器并使其工作。
请求的流程将是: 用户请求-> Spring Cloud网关->微服务
示例 Spring Cloud 网关配置将类似于:
application.yml
spring:
cloud:
gateway:
routes:
- id: msOne
uri: http://localhost:8081/
predicates:
- Path=/ms-one-services/**
filters:
- RewritePath=/ms-one-services(?<segment>/?.*), $\{segment}
- name: CircuitBreaker
args:
name: msOneServices
fallbackUri: forward:/ms-one-services-fallback
- name: Retry
args:
name: msOneServices
retries: 3
statuses: BAD_GATEWAY
backoff:
firstBackOff: 5s
maxBackOff: 20s
factor: 2
basedOnPreviousValue: false
I want to implement retry mechanism along with circuit breaker in spring cloud gateway. Currently when I add Circuit Breaker filter alone to the spring cloud gateway, it works fine. And if I add Retry filter alone, it also works fine. But I want the request to be retried atleast 3 times automatically before the circuit changes to open state. Is there any way that I can integrate both retry and circuit breaker filter and make it work.
The flow of request will be:
User Request -> Spring Cloud Gateway -> Microservice
Sample spring cloud gateway configuration will be like:
application.yml
spring:
cloud:
gateway:
routes:
- id: msOne
uri: http://localhost:8081/
predicates:
- Path=/ms-one-services/**
filters:
- RewritePath=/ms-one-services(?<segment>/?.*), $\{segment}
- name: CircuitBreaker
args:
name: msOneServices
fallbackUri: forward:/ms-one-services-fallback
- name: Retry
args:
name: msOneServices
retries: 3
statuses: BAD_GATEWAY
backoff:
firstBackOff: 5s
maxBackOff: 20s
factor: 2
basedOnPreviousValue: false
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论