【问题标题】:PHP AMQP consumer: Server channel error: 404, message: NOT_FOUNDPHP AMQP 消费者:服务器通道错误:404,消息:NOT_FOUND
【发布时间】: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

【问题讨论】:

    标签: php rabbitmq


    【解决方案1】:

    该异常似乎是由于未声明您的队列引起的(因为错误消息描述了 404 - 未找到队列“操作”)。该示例适用于原始海报的原因可能是因为他之前已经声明了队列,而没有意识到他的示例中缺少它。

    您可以通过在队列对象上调用 ->declare() 来声明队列。您还必须对交换对象执行此操作,除非您在尝试将队列挂接到它时确定它已经存在。

    【讨论】:

    • 你是对的,谢谢。我最初使用 php 库而不是本机扩展,默认情况下,如果尚未声明,该库会生成队列。
    猜你喜欢
    • 2023-03-16
    • 2019-05-25
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2011-09-08
    相关资源
    最近更新 更多