AMQP/RabbitMQ - 仅实时 messages/passthrough 队列
AMQP/RabbitMQ - Only real-time messages/passthrough queue
我正在建立一个接收足球比赛实时更新的网站。我正在使用 RabbitMQ 将更新发送到客户端(JS 网站和 Android/iOS 应用程序)。
客户端应该只接收实时更新。换句话说,客户端应该只在用户登录时接收更新。不保留历史记录。
为了实现这种行为,我正在考虑以下架构:
- RabbitMQ 中的扇出交换。
- 每个用户都有一个专用的队列,绑定到exchange。此队列是在创建用户帐户时创建的。
- 对于这些队列,设置值为0的队列属性
x-message-ttl
。见下文。
- 当用户登录时,客户端消费对应用户的队列
- 消息由后端发送到exchange,并转发到所有队列。当用户未登录时,消息将被立即丢弃,因为
x-message-ttl
设置为 0.
这是 AMQP/RabbitMQ 实现实时通知的正确用法吗?
是和不是 - 你的一些前提是错误的。
In other words, a client should only receive updates when the user is logged in.
当用户未登录时,只需断开与 RMQ 的连接即可。
Each user has a dedicated queue, which is bound to the exchange. This queue is created when the user account is created.
只有在与 RMQ 建立连接后才应创建队列,这样您也涵盖了 When a user is not logged in, the message will be discarded immediately
部分。
- 无需将 TTL 设置为 0。
Messages are sent to the exchange by the backend, and forwarded to all queues
明确一点,是 RabbitMQ "forwarding" 从交换到队列。
我正在建立一个接收足球比赛实时更新的网站。我正在使用 RabbitMQ 将更新发送到客户端(JS 网站和 Android/iOS 应用程序)。
客户端应该只接收实时更新。换句话说,客户端应该只在用户登录时接收更新。不保留历史记录。
为了实现这种行为,我正在考虑以下架构:
- RabbitMQ 中的扇出交换。
- 每个用户都有一个专用的队列,绑定到exchange。此队列是在创建用户帐户时创建的。
- 对于这些队列,设置值为0的队列属性
x-message-ttl
。见下文。 - 当用户登录时,客户端消费对应用户的队列
- 消息由后端发送到exchange,并转发到所有队列。当用户未登录时,消息将被立即丢弃,因为
x-message-ttl
设置为 0.
这是 AMQP/RabbitMQ 实现实时通知的正确用法吗?
是和不是 - 你的一些前提是错误的。
In other words, a client should only receive updates when the user is logged in.
当用户未登录时,只需断开与 RMQ 的连接即可。Each user has a dedicated queue, which is bound to the exchange. This queue is created when the user account is created.
只有在与 RMQ 建立连接后才应创建队列,这样您也涵盖了When a user is not logged in, the message will be discarded immediately
部分。- 无需将 TTL 设置为 0。
Messages are sent to the exchange by the backend, and forwarded to all queues
明确一点,是 RabbitMQ "forwarding" 从交换到队列。