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

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

问题描述

对于不始终支持优先级消息的面向消息的中间件(例如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 Qeueing系统中,实现优先级消息传递的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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