java
Failed to declare queue: yoj.queue1
2024-09-27 17:34:21.256 WARN 2668 --- [ntContainer#0-1] o.s.a.r.listener.BlockingQueueConsumer : Queue declaration failed; retries left=3
org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[yoj.queue1]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:760) [spring-rabbit-2.4.6.jar:2.4.6]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.passiveDeclarations(BlockingQueueConsumer.java:637) [spring-rabbit-2.4.6.jar:2.4.6]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:624) [spring-rabbit-2.4.6.jar:2.4.6]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1376) [spring-rabbit-2.4.6.jar:2.4.6]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1221) [spring-rabbit-2.4.6.jar:2.4.6]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
Caused by: java.io.IOException: null
分析问题:
现在情况,使用了spring-stater-amqp。添加了依赖,使用RabbitListenner编写消费者。启动项目就报错。
Failed to declare queue: yoj.queue1
其中一直提到了定义队列 yoj.queue1失败
所以,应该查看队列是否存在,查看以后,发现确实不存在。
创建队列以后,重启项目,成功运行。
总结:
RabbitMQ显然需要创建队列或者创建队列、交换机、绑定关系以后才能使用,我直接定义了这个队列的监听对象,和调用逻辑而没有编写队列定义或其他定义,显然,队列不存在,所以报错。