使用 node-amqp 模块在 Node.js 中手动确认
我正在使用 postwait 模块 node-amqp 。
我可以向队列发布/订阅一些消息,但我想手动确认这些消息。
例如,我希望读取消息但不确认消息,然后对此消息执行一些计算,然后发送 q.shift()
来确认消息并查看第二条消息。
我希望手动使用确认。
实际上我有一个函数允许使用标志 {ack: false}
进行订阅 然后我有一个函数可以手动创建 q.shift()
(如文档中所述)。
但是当我发布 2 条消息,然后我阅读 2 条消息时,没有确认,我就看到了 2 条消息。但我希望订阅者重复最初收到的相同消息,直到我不确认为止。
我该如何使用这些方法?
I am using the module node-amqp by postwait.
I am able to publish/subscribe to a queue some messages, but I would like to acknowledge the messages manually.
For example, I want the message to be read, and not acknowledged, then to execute some calculation on this message, and THEN send a q.shift()
to acknowledge the message and go through the second message.
I want the acknowledges to be manually used.
Actually I have a function which permits to subscribe with the flag {ack: false}
then I have a function to manually make a q.shift()
(as said in the doc).
But when I publish 2 messages, and then I read 2 messages, without acknowledging, I see the 2 messages. But I would like the subrscribe to repeat the same message that was received at first, until I didn't acknowledge it.
How can I use the methods ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这个问题有点老了,只是在我搜索问题时看到它,
你必须将“ack-flag”设置为 true,只是为了确保你手动确认该消息。 ack: false 表示确认将自动完成
i know this question is kind of old, just saw it when i was searching for a problem
you have to set the "ack-flag" to true, just to make sure that you manually acknowledge the message. ack: false means the acknowledge will be done automatically