SpringBoot中连接RabbitMQ报错An unexpected connection driver error occured

问题

在SpringBoot中,连接RabbitMQ的时候,报错,错误信息大致如下:

2020-08-08 14:42:01.812 ERROR 2780 --- [92.168.1.6:5672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured
java.net.SocketException: socket closed
	at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_181]
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_181]
	at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_181]
	at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_181]
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_181]
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_181]
	at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_181]
	at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-5.4.3.jar:5.4.3]
	at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-5.4.3.jar:5.4.3]
	at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:596) ~[amqp-client-5.4.3.jar:5.4.3]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]

此错误信息,一般是由权限造成的。

排查

登录RabiitMQ控制台,查看:
SpringBoot中连接RabbitMQ报错An unexpected connection driver error occured_第1张图片SpringBoot中连接RabbitMQ报错An unexpected connection driver error occured_第2张图片SpringBoot中连接RabbitMQ报错An unexpected connection driver error occured_第3张图片由上可见,权限是有的(如果没有权限,那么就配置),所以可以确定,是SpringBoot中配置不全造成的。

解决

在SpringBoot的application.properties中添加配置设置虚拟机名称:spring.rabbitmq.virtual-host=my_vhost;最终配置如下:

spring.rabbitmq.host=192.168.1.6
spring.rabbitmq.port=5672
spring.rabbitmq.username=fyk
spring.rabbitmq.password=fyk123
spring.rabbitmq.virtual-host=my_vhost

你可能感兴趣的:(SpringBoot,MQ,SC问题,java,spring,boot,rabbitmq)