【发布时间】:2012-07-15 01:55:55
【问题描述】:
我在 pecl 1.0.3 中使用 amqp 扩展,用 2.7.1 rabbitmq 编译。
我正在尝试使基本的消费者/生产者示例正常工作,但我不断收到错误消息。关于这个扩展的 php 文档很少,而且很多似乎已经过时或错误。
我使用了用户发布的代码,但似乎无法让消费者部分正常工作
连接:
function amqp_connection() {
$amqpConnection = new AMQPConnection();
$amqpConnection->setLogin("guest");
$amqpConnection->setPassword("guest");
$amqpConnection->connect();
if(!$amqpConnection->isConnected()) {
die("Cannot connect to the broker, exiting !\n");
}
return $amqpConnection;
}
发件人:
function amqp_send($text, $routingKey, $exchangeName){
$amqpConnection = amqp_connection();
$channel = new AMQPChannel($amqpConnection);
$exchange = new AMQPExchange($channel);
$exchange->setName($exchangeName);
$exchange->setType("fanout");
if($message = $exchange->publish($text, $routingKey)){
echo "sent";
}
if (!$amqpConnection->disconnect()) {
throw new Exception("Could not disconnect !");
}
}
接收者:
function amqp_receive($exchangeName, $routingKey, $queueName) {
$amqpConnection = amqp_connection();
$channel = new AMQPChannel($amqpConnection);
$queue = new AMQPQueue($channel);
$queue->setName($queueName);
$queue->bind($exchangeName, $routingKey);
//Grab the info
//...
}
然后发送:
amqp_send("Abcdefg", "action", "amq.fanout");
并收到它:
amqp_receive("amq.fanout","action","action");
我一直在运行脚本并指向 amqp 接收问题:
PHP 致命错误:未捕获的异常 'AMQPQueueException' 带有消息“服务器通道错误:404,消息:NOT_FOUND - /home/jamescowhen/test.php:21 中的 vhost '/'' 中没有队列 'action'
谁能指出我正确的方向?整个示例来自此处的用户注释: http://www.php.net/manual/en/amqp.examples.php#109024
【问题讨论】: