Job queue with redis using BLPOP

前端 未结 1 2046
再見小時候
再見小時候 2021-02-05 22:03

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.

1条回答
  •  温柔的废话
    2021-02-05 22:07

    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 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

    Actual re-queueing is left to the application, but this redis command provides the foundations to do so.

    There are also some drop-in-place implementations of queues using redis floating around the web, such as RestMQ [ http://www.restmq.com/ ]

    0 讨论(0)
提交回复
热议问题