Spring Cloud 集成 Rabbit MQ时,提示如下错误Failed to declare exchange: Exchange [name=springCloudBus...

错误详情:

 1 2019-08-11 17:02:16.528  INFO 46912 --- [           main] c.s.b.r.p.RabbitExchangeQueueProvisioner : declaring queue for inbound: springCloudBus.anonymous.206FwSK7QlGAyfjRQ4gUKw, bound to: springCloudBus
 2 2019-08-11 17:02:21.534  WARN 46912 --- [           main] o.s.amqp.rabbit.core.RabbitAdmin         : Failed to declare exchange: Exchange [name=springCloudBus, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
 3 2019-08-11 17:02:21.536 ERROR 46912 --- [127.0.0.1:15672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured
 4 
 5 java.net.SocketException: Socket Closed
 6     at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_131]
 7     at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_131]
 8     at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_131]
 9     at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_131]
10     at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_131]
11     at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_131]
12     at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_131]
13     at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-4.0.2.jar:4.0.2]
14     at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-4.0.2.jar:4.0.2]
15     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571) ~[amqp-client-4.0.2.jar:4.0.2]
16     at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
17 
18 2019-08-11 17:02:26.538  WARN 46912 --- [           main] o.s.amqp.rabbit.core.RabbitAdmin         : Failed to declare queue: Queue [name=springCloudBus.anonymous.206FwSK7QlGAyfjRQ4gUKw, durable=false, autoDelete=true, exclusive=true, arguments={}], continuing... org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
19 2019-08-11 17:02:26.538 ERROR 46912 --- [127.0.0.1:15672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured
20 
21 java.net.SocketException: Socket Closed
22     at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_131]
23     at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_131]
24     at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_131]
25     at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_131]
26     at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_131]
27     at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_131]
28     at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_131]
29     at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-4.0.2.jar:4.0.2]
30     at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-4.0.2.jar:4.0.2]
31     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571) ~[amqp-client-4.0.2.jar:4.0.2]
32     at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
33 2019-08-11 17:02:31.546  WARN 46912 --- [           main] o.s.amqp.rabbit.core.RabbitAdmin         : Failed to declare binding: Binding [destination=springCloudBus.anonymous.206FwSK7QlGAyfjRQ4gUKw, exchange=springCloudBus, routingKey=#], continuing... org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
34 2019-08-11 17:02:36.577 ERROR 46912 --- [127.0.0.1:15672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured

其中,错误摘要如下:

  1. 无法声明exchange:  Failed to declare exchange: Exchange [name=springCloudBus...
  2. 无法连接queue:  Failed to declare queue: Queue
  3. 无法绑定:            Failed to declare binding: Binding [destination=springCloudBus

错误原因:

  在搭建完Rabbit MQ 时,登录URL为localhost:15672,注意,这个端口控制台访问的端口,

  但是在Spring Cloud 集成Rabbit MQ, 此时场景是,应用访问Rabbit MQ,那么此时依旧使用15672,这个控制台登陆端口的话,就出现上述问题

  总结就是,15672只是控制台访问的端口,5672才是应用访问的正确端口。

解决方案:

  根据上述分析,只要在参数配置中,将  spring.rabbitmq.port=15672 修改为 spring.rabbitmq.port=5672 ,即可解决上述问题。

  

 

posted on 2019-08-11 17:25  Cultivate  阅读(5272)  评论(0编辑  收藏  举报

导航