关于Rabbitmq:PHP AMQP使用者:服务器通道错误:404,消息:NOT_FOUND
PHP AMQP consumer: Server channel error: 404, message: NOT_FOUND
我正在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 !\
");
}
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 Fatal error: Uncaught exception ‘AMQPQueueException’ with message ‘Server channel error: 404, message: NOT_FOUND – no queue ‘action’ in vhost ‘/” in /home/jamescowhen/test.php:21
谁能指出我正确的方向? 整个示例来自此处的用户说明:
http://www.php.net/manual/zh/amqp.examples.php#109024
该异常似乎是由于未声明您的队列引起的(因为错误消息描述404-未找到队列”操作”)。 该示例适用于原始海报的原因可能是因为他已经提前声明了队列,但没有意识到示例中缺少该队列。

