问题:在rabbitMQ测试使用手动接收模式时发生 Failed to declare queue错误
: Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80)
: Received a frame on an unknown channel, ignoring it
: Received a frame on an unknown channel, ignoring it
: Received a frame on an unknown channel, ignoring it
: Restarting Consumer@2cd2c8fe: tags=[[amq.ctag-RQecbmbYQjunIZtW-ENloQ]], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@IP:5672/,1), conn: Proxy@1b9ea3e3 Shared Rabbit Connection: SimpleConnection@42257bdd [delegate=amqp://guest@IP:5672/], acknowledgeMode=AUTO local queue size=0
: Failed to declare queue: csnz_queue
: Queue declaration failed; retries left=3
org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[csnz_queue]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:710) [spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.passiveDeclarations(BlockingQueueConsumer.java:594) [spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:581) [spring-rabbit-2.1
现象:
监听器第一次重入队成功,第二次试图重入队发生错误原因
设置的接收模式有问题解决步骤:
1、排查问题:是什么导致了队列消息丢失?2、检查代码
3、更改接收模式配置代码
4、重新测试
5、总结,吸取教训
一、排查问题:是什么导致了队列消息丢失?
最开始报错异常为:Channel shutdown,Failed to declare queue
但是检查了一遍逻辑代码,确认没问题,开始怀疑是不是配置的手动接收模式代码错了
二、检查代码
# 配置RabbitMQ 的基本信息 IP 端口 username pass
spring:
rabbitmq:
host:
port: 5672
username: guest
password: guest
virtual-host: /
listener:
direct:
acknowledge-mode: manual
明明没错啊,acknowledge-mode 就是为 manual,还是idea自动提示补全的呢!
看看别人怎么写这块的
listener.simple.acknowledge-mode = manual
不是吧,居然是 simpl.acknowledge-mode
三、更改接收模式配置代码
# 配置RabbitMQ 的基本信息 IP 端口 username pass
spring:
rabbitmq:
host:
port: 5672
username: guest
password: guest
virtual-host: /
listener:
simple:
acknowledge-mode: manual
四、重新测试
还真tm好了
五、总结,吸取教训
那么 listener.simple.acknowledge-mode 和 listener.direct.acknowledge-mode 究竟有什么区别呢?
搜罗到的信息:
spring.rabbitmq.listener.direct.acknowledge-mode= # 确认容器的模式
spring.rabbitmq.listener.simple.acknowledge-mode= # 确认容器的模式