使用 BLPOP 的 redis 作业队列 [英] Job queue with redis using BLPOP
问题描述
我正在尝试使用 redis 和 ruby eventmachine 创建无限作业队列.为了实现我使用 0 超时的 redis BLPOP 命令.成功 BLPOP 后,我再次运行它.
Im trying to create infinite job queue using redis and ruby eventmachine. To achieve that Im using redis BLPOP command with 0 timeout. After successful BLPOP I run it again.
我是在正确的方式还是有更好的方法来使用 redis 创建作业队列?
Am I on the right way or there is a better way to create job queue with redis?
推荐答案
如果您单独使用 BLPOP 从队列中删除消息,并且您的消息使用者无法处理它,则该消息将不得不重新排队,以免它会随着失败的消费者永远消失.
If you use BLPOP alone to remove a message from the queue, and your message consumer fails to process it, the message will have to be re-queued, lest it disappear forever along with the failed consumer.
为了更持久的消息处理,必须维护一个正在处理的消息列表,以便在发生故障时可以重新排队.
For more durable message processing, a list of messages being processed must be maintained so they can be re-queued in the event of failure.
[B]RPOPLPUSH 非常适合这种情况;它可以原子地从消息队列中弹出消息并将其推送到处理队列,以便应用程序可以在消费者端发生故障的情况下做出响应.
[B]RPOPLPUSH is perfect for this scenario; it can atomically pop a message from the message queue and pushes it onto a processing queue so that the application can respond in the case of a failure on the consumer's end.
http://redis.io/commands/rpoplpush
实际的重新排队由应用程序决定,但是这个 redis 命令提供了这样做的基础.
Actual re-queueing is left to the application, but this redis command provides the foundations to do so.
还有一些使用 redis 的队列的就地实现在网络上浮动,例如 RestMQ [ http://www.restmq.com/ ]
There are also some drop-in-place implementations of queues using redis floating around the web, such as RestMQ [ http://www.restmq.com/ ]
这篇关于使用 BLPOP 的 redis 作业队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!