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

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

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况