在服务器上安装了一个RabbitMq,并新创建了一个用户授予了管理员角色,登录控制台查看一切正常,兴高采烈启动项目进行连接,结果一盆冷水下来,报如下错误:

o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).

org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect

    at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:368) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:573) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1387) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:336) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:1171) ~[spring-rabbit-1.7.4.RELEASE.jar:na]

    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1422) [spring-rabbit-1.7.4.RELEASE.jar:na]

    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]

2018-09-21 14:44:55.695 ERROR [bootstrap,,,] 9248 --- [.168.4.201:5672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured

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:170)

    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:164)

    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571)

    at java.lang.Thread.run(Thread.java:745)

起先以为是配置错误,确认配置没问题后,百度一下,发现是给用户授予了角色,只能登录控制台,但是没有给读写以及管理队列的权限,通过控制台admin按钮查看

 rabbitmq 连接报错 An unexpected connection driver error occured_.net

 

通过命令授权

语法: set_permissions [-p <vhostpath>] <user> <conf> <write> <read>

执行: rabbitmqctl set permissions -p / admin .* .* .* 完成对admin的授权,然后启动项目就正常了

rabbitmq 连接报错 An unexpected connection driver error occured_jar_02