gpt4 book ai didi

RabbitMQ 支持 LIFO 或基于时间的优先级队列

转载 作者:行者123 更新时间:2023-12-05 05:08:40 25 4
gpt4 key购买 nike

有没有办法让 RabbitMQ 队列像堆栈一样工作,即客户端获取队列中发布的最后一条消息(后进先出)而不是第一条消息?或者使用客户端可以设置的时间戳使其成为优先级队列?

RabbitMQ 确实支持优先级队列,但它允许的优先级只是一个最大 255 的数字(建议使用最大 10)。

我想要实现的是首先处理最新的消息,因为它们包含有关源的最新信息。我仍然想处理旧消息,但是在客户端无法跟上的情况下(或者有一些停机时间并且客户端正在恢复)我想先处理最新的状态信息。

到目前为止,我想出的唯一解决方案是对主队列的消息使用 TTL,并在它们过期时让它们进入死信队列,这也由客户端处理。然而,这并不是那么干净,如果消息源发送新状态更新的时间比 TTL 长,则最新状态将滞留在队列中,排在其他仍待处理的旧过期消息之后。

如果用RabbitMQ无法实现,有没有其他推荐的消息框架支持这个需求?

最佳答案

卡夫卡 Log Compaction正是为您描述的用例创建的:

Log compaction ensures that Kafka will always retain at least the last known value for each message key within the log of data for a single topic partition. It addresses use cases and scenarios such as restoring state after application crashes or system failure, or reloading caches after application restarts during operational maintenance. Let's dive into these use cases in more detail and then describe how compaction works.

关于RabbitMQ 支持 LIFO 或基于时间的优先级队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58166635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com