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

本地部署Spring Cloud Data Flow时RabbitMQ连接失败求助

Spring Cloud Data Flow本地部署http | log流RabbitMQ连接超时问题解决

问题场景

在本地Mac部署Spring Cloud Data Flow并创建http | log流后,验证输出时失败:发送curl请求到http源的端口(20100)成功,但无响应体,且http源服务日志中出现RabbitMQ连接超时错误。

执行的核心步骤:

  • 用docker run -d --hostname rabbitmq --name rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:3.7启动RabbitMQ容器,容器运行状态正常
  • 依次启动Skipper Server(2.9.2版本)、DataFlow Server(2.10.2版本)、DataFlow Shell(2.10.2版本)
  • 通过DataFlow仪表盘创建并部署http | log流
  • 发送请求:curl http://localhost:20100 -H "Content-type: text/plain" -d "Happy streaming"

错误日志核心片段:

2023-08-09 03:25:47.057  INFO [http-source,2aa0ce95298cd6b1,db9808ed2bfa4443] 1 --- [oundedElastic-1] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [localhost:5672]
2023-08-09 03:26:47.705 ERROR [http-source,2aa0ce95298cd6b1,f116c3c77334209a] 1 --- [oundedElastic-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint@7a71c2e3]; nested exception is org.springframework.amqp.AmqpIOException: java.net.SocketTimeoutException: connect timed out
...
Caused by: java.net.SocketTimeoutException: connect timed out

原因分析

Mac上Docker默认使用桥接网络,当Data Flow的http源以本地进程方式运行时,它会将localhost:5672解析为本地主机而非RabbitMQ容器。尽管容器端口已映射到本地,但本地进程无法通过localhost直接访问容器内的RabbitMQ服务。

解决方案

方案1:使用Docker容器IP连接

  1. 获取RabbitMQ容器IP
    执行命令:

    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' rabbitmq
    

    记录返回的IP地址(例如172.17.0.2)

  2. 重新启动DataFlow Server
    停止当前运行的DataFlow Server,用以下命令启动(替换<容器IP>为实际获取的地址):

    java -jar spring-cloud-dataflow-server-2.10.2.jar \
      --spring.rabbitmq.host=<容器IP> \
      --spring.rabbitmq.port=5672 \
      --spring.rabbitmq.username=guest \
      --spring.rabbitmq.password=guest
    
  3. 重新部署流
    在DataFlow Shell中执行:

    stream destroy http-ingest
    stream create http-ingest --definition "http | log"
    stream deploy http-ingest
    

方案2:使用Docker内置域名(更简便)

Mac Docker支持host.docker.internal这个特殊域名,它会自动映射到主机的IP,从而间接访问容器服务。直接用以下命令启动DataFlow Server即可:

java -jar spring-cloud-dataflow-server-2.10.2.jar \
  --spring.rabbitmq.host=host.docker.internal \
  --spring.rabbitmq.port=5672

之后同样重新部署流即可。

验证

再次发送curl请求:

curl http://localhost:20100 -H "Content-type: text/plain" -d "Happy streaming"

查看log应用的日志,就能看到Happy streaming的输出。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 19:06:11