java微服务项目超时时间设置

发布于:2024-10-15 ⋅ 阅读:(92) ⋅ 点赞:(0)

nginx+spring cloud gateway+nacos+dubbo+openfeign设置服务处理超时时间

一、nginx:

        keepalive_timeout  30s;     两次写入间隔时间,如果有长时间的处理或者大文件,需要重置此时间,建议长度大于 proxy_read_timeout和proxy_send_timeout
        location / {
            proxy_connect_timeout 5s;   跟代理服务器建立连接的超时时间,一般使用默认
            proxy_read_timeout 30s;      从代理服务器读取响应的超时时间,如果有长时间处理的任务,需要重置此时间
            proxy_send_timeout 30s;   向代理服务器发送请求的超时时间,如果有大文件上传,需要重置此时间
        }

二、gateway:

gateway中使用http调用后端服务的情况:

1、有熔断器,使用熔断器配置,例如使用

spring-cloud-starter-circuitbreaker-reactor-resilience4j组件的CircuitBreaker服务降级组件
spring:
  cloud:
    gateway:
#      httpclient:
#        response-timeout: 2000  如果跟response-timeout同时配置那么这个值需要大于timeoutDuration
      routes:
        - id: account
          uri: lb://account
          predicates:
            - Path=/apiAccount/**
          filters:
            - name: CircuitBreaker
              args:
                name: fallback
                fallbackUri: forward:/fallback




resilience4j:
  timelimiter:
    configs:
      default:
        timeoutDuration: 10s
        cancelRunningFuture: true


2、没有熔断器,默认用Reactor Netty作为http客户端,它是没有设置响应超时时间的,如果需要设置使用:

   spring:
     cloud:
       gateway:
         httpclient:
           response-timeout: 5s  # 或其他适合你的应用的值

gateway和微服务直接如果都是使用dubbo调用则使用:

dubbo:
  consumer:
    check: false
    threads: 500   这个影响并发
    timeout: 10000    这个是响应超时时间

三、微服务之间如果使用openfeign调用:

feign:
  client:
    config:
      default:
        connectTimeout: 5000    这个是建立连接的时间,一般不修改
        readTimeout: 5000   这个是配置响应超时时间


网站公告

今日签到

点亮在社区的每一天
去签到