spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.52k stars 3.32k forks source link

Load balance per route read timeout in spring-cloud-gateway-server-mvc #3378

Open jluiz20 opened 6 months ago

jluiz20 commented 6 months ago

Describe the bug I am migrating our current gateway from zuul to Spring Cloud Gateway Server MVC and I am not sure if it is a bug or just me that is missing something but I am trying to add a timeout for a specific service and I am not able to make it work.

when I define a global timeout, using the following configuration

spring:
  cloud:
    gateway:
      mvc:
        http-client:
          read-timeout: 3s

I get a java.net.SocketTimeoutException but when I define it in the metadata of the simple instance, like below

spring:
  cloud:
    discovery:
      client:
        simple:
          instances:
           my-service:
              - uri: http://localhost:9169
                metadata:
                  read-timeout: 1s

it does not work. I even tried to use the response-timeout from here https://github.com/spring-cloud/spring-cloud-gateway/blob/58c84413f75e01bbef565c4c41b55f633795ad33/docs/modules/ROOT/pages/spring-cloud-gateway/http-timeouts-configuration.adoc#L39-L39 but it seems that is only for the reactive version.

Is there any other way I could set a per-route route read-timeout?

PS: I am setting up a router, like in the samples https://github.com/spencergibb/spring-cloud-gateway-mvc-sample/blob/396005238cec0ad9b66ee01ea7e3006aa6aed5a6/src/main/java/com/example/gatewaymvcsample/Route01FirstRoute.java#L16-L16

    @Bean
    public RouterFunction<ServerResponse> myServiceRouter() {
        return route()
                .route(path("/my-service/**"), http())
                .filter(lb("my-service"))
                //other filters
                .build();
    }

I am currently using spring-cloud-gateway-server-mvc:4.1.2

Thank you for the project and in advance for any help.

spencergibb commented 6 months ago

Metadata read timeout is not built for server webmvc