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.49k stars 3.31k forks source link

What is the meaning and difference between `spring. cloud. gateway.httpclient` and `spring. cloud. gateway.httpserver` ? #2921

Closed Johnny-ZTSD closed 5 days ago

Johnny-ZTSD commented 1 year ago
spring:
  cloud:
    gateway:
      httpserver:
       # org.springframework.cloud.gateway.config.GatewayAutoConfiguration.NettyConfiguration
        wiretap: true
      # org.springframework.cloud.gateway.config.HttpClientProperties
      httpclient:
        wiretap: true
        connectTimeout: 20000
        response-timeout: 10s
        pool:
          type: fixed
          max-connections: 500
          maxLifeTime: 5000
          acquire-timeout: 20000
          max-idle-time: 10000
      discovery:
          filters:    
      default-filters:
        - name: Retry
          args:
            retries: 5
            statuses:
              - BAD_GATEWAY
              - GATEWAY_TIMEOUT   

version

  • spring-cloud-gateway: 2.2.9.RELEASE
  • spring-boot: 2.3.12.RELEASE
  • reactor-netty: 0.9.20.RELEASE
  1. Sorry, I am a freshman of this excellent projects.My situation : After repeatedly reading the source code and network articles of the project, I still have the following questions about the management of internal and external HTTP Connections in the SCG gateway. Can you answer them for me?
  1. I think these problems may also be encountered by other beginners, so I suggest that after answering these questions, developers can reflect them in the corresponding source code comments and explanatory documents.

Thanks~

elkoyote07 commented 1 year ago

Q1. The spring.cloud.gateway.httpclient component is responsible for handling outgoing HTTP requests from the gateway to other services. It provides a customizable HTTP client implementation that allows you to configure things like connection timeouts, maximum connections per route, and SSL settings. This component is used when the gateway is acting as a client to other services.

The 'spring.cloud.gateway.httpserver' component, on the other hand, is responsible for handling incoming HTTP requests from clients and routing them to the appropriate backend services. It provides a customizable HTTP server implementation that allows you to configure things like server ports, SSL settings, and request/response filters. This component is used when the gateway is acting as a server to clients.

In summary, the 'spring.cloud.gateway.httpclient' component is used for making outgoing requests, while the 'spring.cloud.gateway.httpserver' component is used for handling incoming requests.

Q2. To configure the connection timeout for 'spring.cloud.gateway.httpclient', you can set the property 'spring.cloud.gateway.httpclient.connect-timeout' to the desired value in milliseconds.

Q3. As explained in Q2 you can try this option or try to use the next example if you want to custom connection timeout per route:

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

I hope my answer will be helpful. @Johnny-ZTSD

spring-cloud-issues commented 5 days ago

Closing due to age of the question. If you would like us to look at this issue, please comment and we will look at re-opening the issue.