r_hammer
r_hammer

Reputation: 86

Is there a default request timeout in the Spring Cloud Gateway?

In the documentation, I noticed how timeouts can be implemented using Hystrix, but I want to confirm if there is a default timeout already configured.

Upvotes: 5

Views: 8682

Answers (1)

maxeh
maxeh

Reputation: 1593

There is now also a chapter about general timeouts in the documentation. It is possible to set global timeouts and per-route timeouts. I was not able to find the default values, but it seems there is no default timeout at all (HTTP request was in progress for several minutes when I did not include the timeout config). In addition to the spring-cloud-gateway timeouts it is still possible to also use hystrix timeouts, as described for example in this post.

Global timeouts:

spring:
  cloud:
    gateway:
      httpclient:
        connect-timeout: 1000
        response-timeout: 5000

Per-route timeouts:

  - id: per_route_timeouts
    uri: https://example.org
    predicates:
      - name: Path
        args:
          pattern: /delay/{timeout}
    metadata:
      response-timeout: 200
      connect-timeout: 200

Per-route timeouts with Java DSL:

import static org.springframework.cloud.gateway.support.RouteMetadataUtils.CONNECT_TIMEOUT_ATTR;
import static org.springframework.cloud.gateway.support.RouteMetadataUtils.RESPONSE_TIMEOUT_ATTR;

  @Bean
  public RouteLocator customRouteLocator(RouteLocatorBuilder routeBuilder){
     return routeBuilder.routes()
           .route("test1", r -> {
              return r.host("*.somehost.org").and().path("/somepath")
                    .filters(f -> f.addRequestHeader("header1", "header-value-1"))
                    .uri("http://someuri")
                    .metadata(RESPONSE_TIMEOUT_ATTR, 200)
                    .metadata(CONNECT_TIMEOUT_ATTR, 200);
           })
           .build();
  }

Upvotes: 0

Related Questions