doumengxue7371 2015-10-20 16:24
浏览 850
已采纳

rabbitmq,无法将消息发送到特定队列

I'm trying to deliver a message to an exchange and then to a specific queue.

    $conn = new AMQPConnection(RABBITMQ_NODE_IP_ADDRESS, RABBITMQ_PORT, RABBITMQ_USERNAME, RABBITMQ_PASSWORD, RABBITMQ_VHOST);
    $queue = RABBITMQ_QUEUE_CSV;
    $exchange = RABBITMQ_EXCHANGE;
    $ch = $conn->channel();
    $ch->exchange_declare($exchange, 'direct', false, true, false);
    $ch->queue_declare($queue, false, true, false, false);
    $ch->queue_bind($queue, $exchange, $queue);
    $msg = new AMQPMessage(json_encode($params), array('content_type' => 'text/plain', 'delivery_mode' => 2));
    $ch->basic_publish($msg, $exchange);
    $ch->close();
    $conn->close();
    $status = Array("status" => "Job queued");

the type of exchange is 'direct', I have then added a Queue named 'foo_bar' and as 'Routing key' I've used the same 'foo_bar' string.

Just reading the documentation http://www.rabbitmq.com/tutorials/tutorial-four-php.html I cannot understand where I'm doing wrong :(

  • 写回答

1条回答 默认 最新

  • dtmwnqng38644 2015-10-20 21:34
    关注

    Here: $ch->queue_bind($queue, $exchange, $queue); you bind the queue using the $queue routing key.

    Here: $ch->basic_publish($msg, $exchange); you publish a message with an empty routing key. For the message to reach the queue, the routing key on the binding and on the message publication must match

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码