我在 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