dongsu4345 2015-08-06 08:59
浏览 467

消费者如何在不知道php rabbitmq中的队列名称的情况下同时监听通道中存在的所有队列

I am trying to let consumer listen to all queues in nameless exchange in consumer.php but i have to mention queue names as shown:

$this->channel->basic_consume('Cancelcontact', '', false, false, false, false, array($this, 'processMsg'));
$this->channel->basic_consume('Acceptcontact', '', false, false, false, false, array($this, 'processMsg'));
$this->channel->basic_consume('Declinecontact', '', false, false, false, false, array($this, 'processMsg'));

Is there any way to get names of all queues in channel and write single basic consume for same purpose??

  • 写回答

1条回答 默认 最新

  • dousigan0499 2015-08-06 13:21
    关注

    Even if it is possible, it is a bad idea.

    Having multiple queues allows you to have multiple consumers, each of which can handle a particular type of message. By having all of your queues go to the same consumer, your code will have to check the type of message to figure out what to do with it.

    This is a duplication of the work that RabbitMQ has already done for you, and may put you in the mode of "Selective Consumer" - an anti-pattern in RabbitMQ.

    The process of handling an AcceptContact or CancelContact message will be different. Therefore, the code that handles these messages will be different.

    Have the code that handles AcceptContact messages only consume from the AcceptContact queue. Have the code that can handle CancelContact messages only consume from the CancelContact queue.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化