当rabbitmq从队列中删除消息时? [英] when rabbitmq delete message from queue?

查看:73
本文介绍了当rabbitmq从队列中删除消息时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我声明交换,排队并将它们绑定在一起.我基本向这个队列发布一条消息,所以队列中只有你一条消息.此时我启动我的消费者程序(使用 autoAck = true)并调试它,当我运行到 basicConsume(xxx) 时,消息丢失了!在我看来,消费者会在运行到 nextDelivery() 方法时将 basic.ack 发送给代理,但实际上,当我声明消费者时,队列中的消息会被获取.为什么?有人可以告诉我 rabbitmq 何时从队列中删除消息吗?在方法 basicConsume() 或 nextDelivery() 之后???谢谢~~~

First of all i declare exchange,queue and bind them togerther. i basicPublish a message to this queue, so there are one message you in the queue. At this time i start my consumer program(with autoAck = true) and debug it, when i run to basicConsume(xxx), the message was lost! In my opinion consumer will send basic.ack to broker when it run to the method nextDelivery(), but in fact when i will declare a consumer, the message in queue is taken. why? Can someone tell me when rabbitmq delete message from queue? after the method basicConsume() or nextDelivery()??? thx~~~

推荐答案

autoAck = 真

autoAck = true

因为这个

您是在告诉 RabbitMQ 在消息被消费时自动确认该消息.确认一条消息告诉 RabbitMQ 它已被处理,RabbitMQ 现在可以删除它.

you are telling RabbitMQ to automatically acknowledge the message when it is consumed. acknowledging a message tells RabbitMQ that it has been taken care of and RabbitMQ can delete it now.

如果您想在处理完消息后手动确认消息,请将 autoAck 设置为 false.

set autoAck to false if you want to manually acknowledge the message after you are done processing it.

这篇关于当rabbitmq从队列中删除消息时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆