You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JHipster微服务REST API自动重试问题求助(AKS部署环境)

API超时自动重试问题排查与解决

定位重试来源

首先通过日志排查重试发起方:

  • 查看网关日志,确认是否由网关主动发起重试;
  • 查看微服务日志,检查请求是否来自网关/Ingress的多次转发;
  • 使用curl -v调用涉事API,排除浏览器自带的重试机制干扰。

调整JHipster网关配置

JHipster网关基于Spring Cloud Gateway,默认可能启用了重试过滤器,可通过以下方式修改:

1. 全局禁用或调整重试规则

编辑网关的application-prod.yml配置文件:

spring:
  cloud:
    gateway:
      retry:
        enabled: false  # 直接关闭全局重试
        # 如需精细控制,可替换为以下配置(按需调整):
        # retries: 0
        # statuses: 500,502,503,504  # 仅对指定状态码重试,移除超时相关触发条件
        # exceptions: java.io.IOException  # 移除TimeoutException,避免超时触发重试

2. 检查特定路由的重试过滤器

查看路由配置中是否存在Retry过滤器,若有则调整或移除:

spring:
  cloud:
    gateway:
      routes:
        - id: your-service-route
          uri: lb://your-service
          predicates:
            - Path=/api/**
          filters:
            # 移除或调整以下Retry过滤器配置
            # - name: Retry
            #   args:
            #     retries: 3
            #     statuses: BAD_GATEWAY

调整AKS NGINX Ingress配置

AKS默认使用NGINX Ingress Controller,需调整超时和重试规则:

1. 单个Ingress资源配置

在Ingress注解中添加超时设置并禁用上游重试:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: gateway-ingress
  annotations:
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "120"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "120"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "120"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_next_upstream off;  # 禁止NGINX重试后端服务
spec:
  # 原有Ingress规则

2. 全局Ingress Controller配置

修改Controller的ConfigMap(通常在kube-system命名空间):

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
data:
  proxy-connect-timeout: "120s"
  proxy-read-timeout: "120s"
  proxy-send-timeout: "120s"
  proxy-next-upstream: "off"

修改后需重启Ingress Controller Pod生效。

检查微服务Feign重试配置

若网关通过Feign调用微服务,Feign默认会在超时/错误时重试,可通过以下方式禁用:

1. 代码配置

添加Feign配置类:

@Configuration
public class FeignRetryConfig {
    @Bean
    public Retryer feignRetryer() {
        return Retryer.NEVER_RETRY;
    }
}

2. 配置文件调整

在application.yml中设置:

feign:
  client:
    config:
      default:
        retryer:
          maxAttempts: 1  # 仅尝试1次,不重试

排除浏览器重试机制

使用curl发起请求测试:

curl -v -X GET https://your-api-domain/long-running-endpoint

若curl调用无重试,说明是浏览器自动重试(如Chrome对超时GET请求的重试),需前端添加请求控制逻辑。

内容的提问来源于stack exchange,提问作者Venky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 18:42:45