Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis Pub/Sub Ack/Nack

Is there a concept of acknowledgements in Redis Pub/Sub?

For example, when using RabbitMQ, I can have two workers running on separate machines and when I publish a message to the queue, only one of the workers will ack/nack it and process the message.

However I have discovered with Redis Pub/Sub, both workers will process the message.

Consider this simple example, I have this go routine running on two different machines/clients:

go func() {
    for {
        switch n := pubSubClient.Receive().(type) {
        case redis.Message:
            process(n.Data)
        case redis.Subscription:
            if n.Count == 0 {
                return
            }
        case error:
            log.Print(n)
        }
    }
}()

When I publish a message:

conn.Do("PUBLISH", "tasks", "task A")

Both go routines will receive it and run the process function.

Is there a way of achieving similar behaviour to RabbitMQ? E.g. first worker to ack the message will be the only one to receive it and process it.

like image 759
Richard Knop Avatar asked Aug 16 '15 17:08

Richard Knop


1 Answers

Redis PubSub is more like a broadcast mechanism.

if you want queues, you can use BLPOP along with RPUSH to get the same interraction. Keep in mind, RabbitMQ does all sorts of other stuff that are not really there in Redis. But if you looking for simple job scheduling / request handling style, this will work just fine.

like image 108
David Budworth Avatar answered Oct 29 '22 12:10

David Budworth