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

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 :(

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将消息传递给交换机,然后传递给特定队列。

  $ 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”); 
   
 
 

交换类型是“直接”,然后我添加了一个名为Queue的队列 'foo_bar'和'路由键'我使用了相同的'foo_bar'字符串。

只需阅读文档 http://www.rabbitmq.com/tut orials / tutorial-four-php.html 我无法理解我做错了什么:(

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题