IT评测·应用市场-qidao123.com
标题:
SpringBoot毗连rabbitmq 报错 An unexpected connection driver error occurred
[打印本页]
作者:
傲渊山岳
时间:
2025-3-20 13:22
标题:
SpringBoot毗连rabbitmq 报错 An unexpected connection driver error occurred
SpringBoot在启动时报错,毗连不上rabbitmq,报错内容如下
24-09-30.13:36:02.406 [AMQP Connection 47.121.218.83:5672] ERROR ForgivingExceptionHandler - An unexpected connection driver error occurred
java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:184)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:665)
at java.lang.Thread.run(Thread.java:748)
24-09-30.13:36:02.407 [RMI TCP Connection(2)-192.168.1.110] WARN RabbitHealthIndicator - Rabbit health check failed
org.springframework.amqp.AmqpIOException: java.io.IOException
复制代码
办理方法
1. 创建一个用户
参考:An unexpected connection driver error occured错误(亲测有效)-CSDN博客
添加一个用户:
查看test的详情:
添加权限:
2. 设置文件添加 virtual-host,具体如下:
我使用的项目依赖是spring-boot-starter-amqp,这个依赖紧张用于简化在Spring Boot应用中集成AMQP协议相关功能的过程,比如与RabbitMQ服务器进行消息通信等场景。通过引入这个依赖,开辟者可以更方便地使用Spring Boot来开辟支持消息队列的应用程序。
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-amqp -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>3.2.0</version>
</dependency>
复制代码
设置文件:
# Spring 配置;rabbitmq
spring:
rabbitmq:
addresses: 127.0.0.1
port: 5672
username: test
password: test
listener:
simple:
prefetch: 1 # 每次投递n个消息,消费完在投递n个
topic:
activity_sku_stock: activity_sku_stock
# virtual-host 是一个逻辑隔离单位,用于将不同的应用程序或环境隔离开来。
# virtual-host: master 表示应用程序将连接到名为 master 的虚拟主机。
virtual-host: master
复制代码
[code][/code]
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/)
Powered by Discuz! X3.4