如何仅使用消息 ID(在 Go 中)确认 Rabbitmq 消息?
How can I acknowledge a Rabbitmq message using the message id only (in Go)?
我构建了一个小型服务器 (golang) 来从 RabbitMQ 获取消息并通过 Websocket 将它们传送到连接的浏览器。
它工作得很好,但有一个警告:消息在通过 websocket 传递到浏览器时得到确认。对于大多数消息来说没问题,但有些消息可能非常重要。如果用户的浏览器收到这些消息但用户没有看到该消息,则在浏览器关闭或重新加载时消息将丢失。
有没有办法根据消息 ID(来自 Delivery 结构)稍后确认消息?
用例是 一些 消息在用户明确确认时被确认,此时消息 ID 被发送回工具以使用 RabbitMQ 确认。
即使你能做到这一点,也是糟糕的设计。
如果用户看不到消息,消息会怎样?您的 Web 服务器会无限期地挂在它上面吗?是否 "nack" 将消息返回队列?
这两个选项都不好。
坚持每条消息,RabbitMQ 将开始遇到来自大量用户的数千条未确认消息的问题。 Nack 将消息返回队列,您将在循环中反复处理消息,激增 Web 服务器和 RMQ 服务器上的 CPU 资源,以及两者之间的网络流量。
解决此问题的更好方法是将消息从 RabbitMQ 中提取出来后,将其存储在数据库中。当它被发送到浏览器/被浏览器查看时,更新数据库以反映这一点。
摘自我写的一篇尚未发表的文章:
Store the message in a database.
Add a field to the database record that says who this message belongs
to. When the user reconnects later, query the database for any
messages that this user needs to see and send them along at that time.
The full process started above, then becomes this:
- User's browser connects to SignalR/Socket.io/Pusher/websockets on web
server
- Web server checks a queue for updates that happen during a long
running process
- When a message for a logged in user comes in
- If the
user is logged in, broadcast the message through the websocket to the
user
- If the user is not logged in, store the message in a database
- When the user logs in again, query the database and send all waiting
messages
It's what you would have done before the idea of a message
queue came in to play, right? It should be what you would do now that
you have a message queue, as well.
我构建了一个小型服务器 (golang) 来从 RabbitMQ 获取消息并通过 Websocket 将它们传送到连接的浏览器。
它工作得很好,但有一个警告:消息在通过 websocket 传递到浏览器时得到确认。对于大多数消息来说没问题,但有些消息可能非常重要。如果用户的浏览器收到这些消息但用户没有看到该消息,则在浏览器关闭或重新加载时消息将丢失。
有没有办法根据消息 ID(来自 Delivery 结构)稍后确认消息?
用例是 一些 消息在用户明确确认时被确认,此时消息 ID 被发送回工具以使用 RabbitMQ 确认。
即使你能做到这一点,也是糟糕的设计。
如果用户看不到消息,消息会怎样?您的 Web 服务器会无限期地挂在它上面吗?是否 "nack" 将消息返回队列?
这两个选项都不好。
坚持每条消息,RabbitMQ 将开始遇到来自大量用户的数千条未确认消息的问题。 Nack 将消息返回队列,您将在循环中反复处理消息,激增 Web 服务器和 RMQ 服务器上的 CPU 资源,以及两者之间的网络流量。
解决此问题的更好方法是将消息从 RabbitMQ 中提取出来后,将其存储在数据库中。当它被发送到浏览器/被浏览器查看时,更新数据库以反映这一点。
摘自我写的一篇尚未发表的文章:
Store the message in a database.
Add a field to the database record that says who this message belongs to. When the user reconnects later, query the database for any messages that this user needs to see and send them along at that time.
The full process started above, then becomes this:
- User's browser connects to SignalR/Socket.io/Pusher/websockets on web server
- Web server checks a queue for updates that happen during a long running process
- When a message for a logged in user comes in
- If the user is logged in, broadcast the message through the websocket to the user
- If the user is not logged in, store the message in a database
- When the user logs in again, query the database and send all waiting messages
It's what you would have done before the idea of a message queue came in to play, right? It should be what you would do now that you have a message queue, as well.