dongqiao8502 2015-08-16 17:11
浏览 949
已采纳

Redis发布/订阅确认/小结

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.

  • 写回答

2条回答 默认 最新

  • dsafq2131321 2015-08-16 19:58
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改