在 FIFO 队列系统中,实现优先消息传递的最佳方式是什么? [英] In a FIFO Qeueing system, what's the best way the to implement priority messaging

查看:42
本文介绍了在 FIFO 队列系统中,实现优先消息传递的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于不始终支持优先级消息的面向消息的中间件(例如 AMQP),当队列只有 FIFO 语义时,实现优先级消费的最佳方法是什么?一般用例是这样一种系统,其中当队列中存在大量消息积压时,消费者会在收到较低优先级消息之前收到较高优先级的消息.

For message-oriented middleware that does not consistently support priority messages (such as AMQP) what is the best way to implement priority consumption when queues have only FIFO semantics? The general use case would be a system in which consumers receive messages of a higher priority before messages of a lower priority when a large backlog of messages exists in Queue(s).

推荐答案

鉴于给定的单个队列仅支持 FIFO,您当然必须引入多个队列、中介或具有更复杂的消费者.

Given only FIFO support for a given single queue, you will of course have to introduce either multiple queues, an intermediary, or have a more complex consumer.

可以通过多种方式处理多个队列.生产者和消费者可以同意在他们之间有两个队列,一个用于高优先级,一个用于后台任务.

Multiple queues could be handled in a couple of ways. The producer and consumer could agree to have two queues between them, one for high-priority, and one for background tasks.

如果您的生产者受限于单个队列,但您可以控制消费者,请考虑在路径中引入扇出路由器.所以生产者->路由器是一个单一的队列,然后路由器有两个队列到消费者.

If your producer is constrained to a single queue, but you have control over the consumer, consider introducing a fan-out router in the path. So producer->Router is a single queue, and the router then has two queues to the consumer.

另一种可能不太理想的解决方法是让您的消费者旋转一个线程到队列前面,然后在内部分派工作.类似于上面的路由器版本,但在单个应用程序中.这有一个缺点,即在您的应用内有多个消息正在传输,这可能会使发生故障时的恢复复杂化.

Another way to tackle it, which is likely less than ideal, would be to have your consumer spin a thread to front the queue, then dispatch the work internally. Something like the router version above, but inside a single app. This has the downside of having multiple messages in flight inside your app, which may complicate recovery in the event of a failure.

不要忘记考虑有效的低优先级事件的饥饿,不管它们是什么,如果其中一些应该被处理,即使有更高优先级的事件仍然悬而未决.

Don't forget to consider starvation of the effectively low-priority events, whatever they are, if some of them should be processed even if there are higher-priority events still hanging about.

这篇关于在 FIFO 队列系统中,实现优先消息传递的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆