springboot连接rabbitmq启动时报如下错误:
-
Starting DemoApplication on yangyuedeMacBook-Pro.local with PID 11332 (/Users/yangle/lesson/code_learning/target/classes started by yangle in /Users/yangle/lesson/code_learning)
2020-11-14 10:40:38.843 INFO 11332 — [ main] com.lezai.DemoApplication : No active profile set, falling back to default profiles: default
2020-11-14 10:40:39.470 INFO 11332 — [ main] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [127.0.0.1:5672]
2020-11-14 10:40:39.491 WARN 11332 — [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Socket closed)
2020-11-14 10:40:39.491 INFO 11332 — [ main] o.s.a.r.l.SimpleMessageListenerContainer : Broker not available; cannot force queue declarations during start: java.io.IOException
2020-11-14 10:40:39.495 INFO 11332 — [ntContainer#0-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [127.0.0.1:5672]
2020-11-14 10:40:39.500 WARN 11332 — [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Socket closed)
2020-11-14 10:40:39.506 INFO 11332 — [ main] com.lezai.DemoApplication : Started DemoApplication in 0.906 seconds (JVM running for 1.475)
2020-11-14 10:40:44.607 INFO 11332 — [ntContainer#0-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting [email protected]: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2020-11-14 10:40:44.608 INFO 11332 — [ntContainer#0-2] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [127.0.0.1:5672]
2020-11-14 10:40:44.616 WARN 11332 — [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Socket closed)
2020-11-14 10:40:49.710 INFO 11332 — [ntContainer#0-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting [email protected]: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2020-11-14 10:40:49.711 INFO 11332 — [ntContainer#0-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [127.0.0.1:5672]
2020-11-14 10:40:49.721 WARN 11332 — [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Socket closed)
解决方案
- 检查用户名和密码是否写对
- 检查appliction配置文件中 spring.rabbitmq.virtual-host 配置的值是否带上了“/”,如果带上了,请去除掉,这是最容易犯的错误
- 检查端口号是否配置对,如果按照默认设置的端口号来说的话,访问控制的端口号时15672,但是通过代码连接mq的时候使用的时5672,一定要注意,否则不会连接成功的
- 检查当前用户是否对所连接的host有读写权限,如果没有请加上
微信搜一搜【乐哉开讲】关注帅气的我,回复【干货领取】,将会有大量面试资料和架构师必看书籍等你挑选,包括java基础、java并发、微服务、中间件等更多资料等你来取哦。