http://stackoverflow.com/questions/30696351/a-single-channel-with-multiple-consumers-rabbitmq

Typically the IModel.BasicConsume() registration is used to connect a single consumer through a single channel. However, the documentation is clear that multiple consumers can be registered through a single channel. For example:

Channel channel = ...;
Consumer consumer1 = ...;
Consumer consumer2 = ...;
channel.basicQos(10); // Per consumer limit
channel.basicConsume("my-queue1", false, consumer1);
channel.basicConsume("my-queue2", false, consumer2);

The above snippet is taken from this link. The documentation goes on to clarify the disadvantage of doing this:

Each Channel has its own dispatch thread. For the most common use case of one Consumer per Channel, this means Consumers do not hold up other Consumers. If you have multiple Consumers per Channel be aware that a long-running Consumer may hold up dispatch of callbacks to other Consumers on that Channel.

The disadvantage is spelled out clearly. What is missing is the explanation of why positively it may be useful to do this. Does anyone know? What is the advantage?

Furthermore, there is another similar scenario to consider. Evidently it is also possible to multiply register the same consumer.

Channel channel = ...;
Consumer consumer = ...;
channel.basicConsume("my-queue1", false, "queue1-Tag", consumer);
channel.basicConsume("my-queue2", false, "queue2-Tag", consumer);

In this latter case it is actually easier to envision the advantage; it allows multiple Rabbit queues to be multiplexed into a single event stream. But if it has that advantage, why is this approach so esoteric and completely undocumented? What makes this particularly weird is that the whole idea of a consumerTag ("queue1-Tag" and "queue2-Tag") seems to exist to support this scenario. Please note:

Is it possible for one consumer (one QueueingBasicConsumer) to register to multiple queues and have messages continually sent to it?

Certainly it is. When registering a Consumer you (either nominate, or) get a (server-generated) consumer tag, essentially an identifier for the Consumer. You only have to keep a map of tags so that the Consumer can know (when it is called) for which registration this callback is being made.

If you have a single channel connection to RabbitMQ, then the Consumers (each registration looks like a Consumer to the server) get called serially, so there is no concurrency. If you have many channels you can register for different queues on different channels and the distinct channels' callbacks can run concurrently.

The above Q&A came from this link.

If this is why consumerTag identifiers are used, why is this not stated clearly in the official documentation?

So to review the two scenarios:

  • What is the advantage of having multiple consumers registered through a single channel?
  • Why are multiple registrations of a single consumer practically discussed nowhere, even though it provides a seemingly self-evident benefit?

I'm coding in the context of .net and C#, though this question is really about RabbitMQ in general.

最新文章

  1. BootLoader的架构设计
  2. linux下的目录结构和内容
  3. 【安全测试】burpsuite安装方法
  4. CUBRID学习笔记 9 创建示例数据库
  5. DBA_Oracle LogMiner分析重做和归档日志(案例)
  6. [学习笔记]设计模式之Abstract Factory
  7. 使用第三方SDK出现: duplicate symbol _llvm.cmdline in:
  8. JS - 图片放大器
  9. linux系统启动过程的列表
  10. sublimeserver启动本地服务器(sublime text)
  11. Mycat 分布式事务的实现
  12. [Luogu3676]小清新数据结构题
  13. Form 表单提交的几种方式
  14. 【webpack学习笔记】a01-基础构建
  15. JumpServer 安装配置
  16. PAT 乙级 1089 狼人杀 && 1090 危险品装箱 (我的时间最短哦)
  17. 第 7 章 多主机管理 - 047 - 管理 Machine
  18. 剑指offer总结
  19. openfalcon源码分析之agent
  20. json格式的一些常用操作方法

热门文章

  1. golang 解析json 动态数组
  2. spring注解开发-扩展原理(源码)
  3. JS实现两版本号大小比较
  4. POJ-2442-Sequence(二叉堆)
  5. openjudge-4017 爬楼梯
  6. 如何用纯 CSS 创作一个容器厚条纹边框特效
  7. CentOS6.8下安装Docker
  8. Spring入门(1)——搭建简单的环境
  9. 「BZOJ1537」Aut – The Bus(变形Dp+线段树/树状数组 最优值维护)
  10. CactiI表结构和数据被动获取