WebFlux Netty 应用程序对 WebClient 请求使用错误的端口

问题描述 投票:0回答:1

我有 Spring Boot WebFlux 应用程序在端口 8080 上工作,并且执行器运行状况端点在 application.yml 中配置为 8081:

server:
  port: 8080
  address: 127.0.0.1
logging:
  level:
    reactor:
      netty:
        http: TRACE
management:
  endpoints:
    web:
      base-path: /
      path-mapping:
        health: health
  server:
    port: 8081

本地一切正常,在日志中我看到它使用正确的端口(L:/127.0.0.1:8080):

2023-10-22T15:50:14.591+02:00 DEBUG 20860 --- [ctor-http-nio-3] r.n.http.server.HttpServerOperations     : [9b5ca968, L:/127.0.0.1:8080 - R:/127.0.0.1:64169] New http connection, requesting read
2023-10-22T15:50:14.604+02:00 DEBUG 20860 --- [ctor-http-nio-3] r.n.http.server.HttpServerOperations     : [9b5ca968, L:/127.0.0.1:8080 - R:/127.0.0.1:64169] Increasing pending responses, now 1

但是一旦部署到 AWS,它就会使用 8081 并且不连接到任何地址,这会导致超时连接错误。

有没有办法手动设置 Netty/WebClient 的本地端口以用于 WebClient 请求? 我尝试了多个 HttpClient 和 WebClient 配置,但没有一个起作用。

据我从我的团队了解到,我们公司中使用 WebClient/RestTemplate 和 Tomcat 的其他应用程序在同一 AWS 空间上运行没有任何问题,所以我认为它需要通过应用程序配置来解决

spring-boot http spring-webflux netty spring-webclient
1个回答
0
投票

使用

127.0.0.1
有什么意义?对于本地开发,
Netty
将自动在本地主机中启动,因此指定地址是多余的。对于云来说,这是多余的,因为是云为您获取服务的 IP。您可能会做的是将静态 IP 分配给您的应用程序,但这是另一回事了。从
application.yml
中删除 IP,并为云提供商实时选择 IP。如果您必须在同一台“机器”中运行多个应用程序,可以说更改
application.yml
中的端口,这样它们就不会发生冲突。

© www.soinside.com 2019 - 2024. All rights reserved.