小编Ben*_*hey的帖子

如何配置 spring-cloud-gateway 使用 sleuth 记录请求/响应正文

我希望开发一个基于 spring-cloud-gateway:2.0.2-RELEASE 的网关服务器,并希望利用 sleuth 进行日志记录。自从我写入日志时,我就开始运行 Sleuth,我看到 Sleuth 详细信息(跨度 ID 等),但我希望看到自动记录的消息正文。我需要做些什么才能让 Sleuth 使用 Spring-Cloud-Gateway 记录开箱即用的请求/响应吗?

这是到达我的下游服务的请求标头

    标题:
       { 'x-request-foo': '2a9c5e36-2c0f-4ad3-926c-cb20d4428462',
         转发: 'proto=http;host=localhost;for="0:0:0:0:0:0:0:1:51720"',
         'x-forwarded-for': '0:0:0:0:0:0:0:1',
         'x-forwarded-proto': 'http',
         'x-转发端口': '80',
         'x-转发主机': '本地主机',
         'x-b3-traceid': '5bd33eb8050c7a32dfce6adfe68b06ca',
         'x-b3-spanid': 'ba202a6d6f3e2893',
         'x-b3-parentspanid': 'dfce6adfe68b06ca',
         'x-b3-采样': '0',
         主机:'本地主机:8080'},

网关服务中的 Gradle 文件..

    构建脚本{
        分机{
            kotlin版本 = '1.2.61'
            springBootVersion = '2.0.6.RELEASE'
            springCloudVersion = 'Finchley.RELEASE'
        }
    }
    依赖管理{
        进口{
            mavenBom“org.springframework.cloud:spring-cloud-sleuth:2.0.2.RELEASE”
            mavenBom 'org.springframework.cloud:spring-cloud-gateway:2.0.2.RELEASE'
            mavenBom“org.springframework.cloud:spring-cloud-dependency:$ {springCloudVersion}”
        }
    }
    依赖项{
        实现('org.springframework.cloud:spring-cloud-starter-sleuth')
        实现('org.springframework.cloud:spring-cloud-starter-gateway')
        实现(“org.jetbrains.kotlin:kotlin-stdlib-jdk8”)
        实现(“org.jetbrains.kotlin:kotlin-reflect”)
        testImplementation('org.springframework.boot:spring-boot-starter-test')
    }

最后是网关服务的 application.yml 文件...

    服务器:
      小服务程序:
        上下文路径:/
      端口:80
    春天:
      应用:
        名称:api.gateway.ben.com …

spring-cloud-sleuth spring-cloud-gateway

7
推荐指数
1
解决办法
8768
查看次数

如何为 Spring WebFlux 配置 netty 连接超时

我在 AWS 负载均衡器后面运行 spring cloud gateway(我理解它是在 Spring Webflux 上构建的),并且我收到间歇性 502 错误。经过调查,问题似乎与负载均衡器和我的节点之间的连接超时有关。从一些调查来看,底层 netty 服务器的默认超时时间为 10 秒。我使用以下命令确定了这一点...

time nc -vv 10.10.xx.xxx 5100
Connection to 10.10.xx.xxx 5100 port [tcp/*] succeeded!

real    0m10.009s
user    0m0.000s
sys     0m0.000s
Run Code Online (Sandbox Code Playgroud)

虽然我可以将负载均衡器上的 idleTimeout 设置在 10 秒以内,但这感觉非常低效。如果可能,我想将其保持在 30 秒以上。相反,我想增加 netty 服务器上的连接超时。我试图在我的 application.yml 中设置 server.connection-timeout 属性...

server:
  connection-timeout: 75000
Run Code Online (Sandbox Code Playgroud)

也通过指定秒...

server:
  connection-timeout: 75s
Run Code Online (Sandbox Code Playgroud)

但是当我运行 time 命令以查看我的连接持续多长时间时,超时没有变化,它仍然以 10 秒结束......

time nc -vv 10.10.xx.xxx 5100
Connection to 10.10.xx.xxx 5100 port [tcp/*] succeeded!

real    0m10.009s
user    0m0.000s
sys     0m0.000s
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么?

reactor-netty spring-webflux spring-cloud-gateway

5
推荐指数
1
解决办法
6980
查看次数