Reputation: 523
Is there a way to set different timeout values for each route in Spring cloud gateway? eg /route1 - 30s /route2 - 20s
Upvotes: 2
Views: 6231
Reputation: 1164
According to Spring Cloud Gateway documentation this is much simpler:
https://cloud.spring.io/spring-cloud-gateway/reference/html/#per-route-timeouts
So you can configure connect and read timeouts per each route, like this:
- id: per_route_timeouts
uri: https://example.org
predicates:
- name: Path
args:
pattern: /delay/{timeout}
metadata:
response-timeout: 200
connect-timeout: 200
Upvotes: 2
Reputation: 1037
Yes, We can do the same by defining different hystrix
command for different routes. Consider the following example, where for route_1
the timeout is 15 seconds, as the hystrix
command used here default
is configured with a timeout of 15 seconds.
# ===========================================
# Timeout 15 seconds
- id: route_1
uri: ${test.uri}
predicates:
- Path=/timeout/**
filters:
- name: Hystrix
args:
name: default
fallbackUri: forward:/hystrixfallback
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 15000
Now for route_2
the the hystrix
command used is applicationTimeOut
with a timeout of 5 seconds.
# ===========================================
# Timeout 5 seconds
- id: route_2
uri: ${test.uri}/count
predicates:
- Path=/count
filters:
- name: Hystrix
args:
name: applicationTimeOut
fallbackUri: forward:/hystrixfallback
hystrix.command.applicationTimeOut.execution.isolation.thread.timeoutInMilliseconds: 5000
Now for route_3
the the hystrix
command used is apiTimeOut
with a timeout of 2 seconds.
# ===========================================
# Timeout 2 seconds
- id: route_3
uri: ${test.uri}
predicates:
- Path=/event/**
filters:
- name: Hystrix
args:
name: apiTimeOut
fallbackUri: forward:/hystrixfallback
hystrix.command.apiTimeOut.execution.isolation.thread.timeoutInMilliseconds: 2000
Upvotes: 3