在NSQ中确认消息

发布于 2025-01-20 06:27:41 字数 380 浏览 3 评论 0原文

我是 NSQ 的新手,想知道是否可以确认消息已被消耗(就像在 Google PubSub 中一样)。我正在使用 Golang,并在浏览 NSQ 文档时(https://github.com/nsqio/nsq/blob/v1.2.1/nsqd/channel.go#L350)我找到了方法FinishMessage 根据其注释,它应该成功丢弃正在传输的消息。这是否就等于承认了?如果一条消息在 NSQ 中没有被确认,如何确保它一旦被消费就消失了,这样就不会被再次消费?

谢谢

I'm new to NSQ and was wondering whether it is possible to acknowledge that a message was consumed (just like in Google PubSub). I'm using Golang, and while going through the NSQ documentation (https://github.com/nsqio/nsq/blob/v1.2.1/nsqd/channel.go#L350) I've found the method FinishMessage which according to its comment, it's supposed to successfully discards an in-flight message. Would that be considered the same as acknowledged? If a message is not acknowledged in NSQ, how is it ensured it's gone once consumed so it won't be consumed over again?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海蓝天 2025-01-27 06:27:41

NSQ 在将消息发送给消费者后自动从队列中删除消息。如果在设置的超时后消费者没有响应,则自动重新排队消息。

是的,根据您使用的编程语言客户端,您必须发送“完成”。
这是 Golang 的文档
https://pkg.go.dev/github.com/nsqio/ go-nsq#Finish

但由于 NSQ 的设计方式,如果预期操作不成功,您必须重新排队来自应用程序的消息。

这是他们网站的摘录

NSQ 保证消息至少被传递一次,尽管可能存在重复消息。消费者应该预料到这一点并进行重复数据删除或执行幂等操作。

此保证作为协议的一部分强制执行,工作原理如下(假设客户端已成功连接并订阅主题):

  1. 客户端表示他们已准备好接收消息
  2. NSQ 发送消息并在本地临时存储数据(以防重新排队或超时)
  3. 客户端回复FIN(完成)或REQ(重新排队),分别指示成功或失败。如果客户端没有回复 NSQ 将超时
    可配置的持续时间并自动重新排队消息)

您可以在此处阅读更多信息:https://nsq.io /overview/design.html

希望我的回答对您有所帮助。

NSQ automatically removes a message from the queue after sending it to a consumer. And automatically re-queues the message if there is no response from the consumer after a set timeout.

And yes, depending on which programming language client you are using you have to send 'finish'.
Here are the docs for Golang
https://pkg.go.dev/github.com/nsqio/go-nsq#Finish

But because of the way NSQ is designed you have to re-queue a message from your app if the intended action was not successful.

Here is an excerpt from their website

NSQ guarantees that a message will be delivered at least once, though duplicate messages are possible. Consumers should expect this and de-dupe or perform idempotent operations.

This guarantee is enforced as part of the protocol and works as follows (assume the client has successfully connected and subscribed to a topic):

  1. client indicates they are ready to receive messages
  2. NSQ sends a message and temporarily stores the data locally (in the event of re-queue or timeout)
  3. client replies FIN (finish) or REQ (re-queue) indicating success or failure respectively. If client does not reply NSQ will timeout after
    a configurable duration and automatically re-queue the message)

You can read more here: https://nsq.io/overview/design.html

Hope my answer helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文