【问题标题】:php get message from rabbitmq errorphp从rabbitmq错误中获取消息
【发布时间】:2012-03-15 07:13:58
【问题描述】:

我的 amqp 扩展版本是 1.0.1 & AMQP 协议版本是 0-9-1

从队列中获取消息:

<?php
try {
$conn = new AMQPConnection() ;
$conn->setLogin('guest') ;
$conn->setPassword('guest') ;
$conn->connect() ;
if ($conn->isConnected()) {
    $channel = new AMQPChannel($conn) ;
    if ($channel->isConnected())
    {
        $queue = new AMQPQueue($channel) ;
        $queue->setName('test_queue') ;
        $queue->setFlags(AMQP_DURABLE | AMQP_AUTODELETE) ;
        $queue->declare() ;
        $messages = $queue->get(AMQP_AUTOACK) ;
        print_r($messages->getBody()) ;
    }
} else {
    echo "connect failure ... " ;
}
$conn->disconnect() ;} catch (Exception $e) {
echo $e->getMessage() ;}?>

它不起作用..

Server channel error: 406, message: PRECONDITION_FAILED - parameters for queue 'test_queue' in vhost '/' not equivalent

【问题讨论】:

    标签: php rabbitmq


    【解决方案1】:

    在我看来,队列已经存在,并且之前在 vhost 中使用不同的参数声明(创建)了它。队列需要每次都使用相同的参数准确地声明(或删除并使用所需的参数重新创建)。尝试通过管理插件 (http://www.rabbitmq.com/management.html) 删除队列,然后再次运行您的脚本

    【讨论】:

      【解决方案2】:

      如果您的队列已经创建,则无需创建它(使用“声明”方法)并再次与交换绑定。恕我直言,您不应该这样做 a) 这些操作需要管理权限 b) 只需执行一次就足够了 c) 您可能没有生产管理权限,并且您的代码会被破坏。 我认为最好使用管理控制台或您喜欢的任何其他工具创建和绑定所有必需的队列,然后以这种方式接收消息

      // consider using connection more than once. that's only for illustration purposes.
      $connection = new AMQPConnection([ put your credentials here ]);
      $connection->connect();
      if(!$connection->isConnected()) {
          throw new Exception('Connection failed.');
      }
      
      $chnlObj = new AMQPChannel($connection);
      $queObj  = new AMQPQueue($chnlObj);
      $queObj->setName('yourQueueName');
      echo $queObj->get(AMQP_AUTOACK)->getBody();
      
      // consider using connection more than once. that's only for illustration purposes.
      $connection->disconnect();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-18
        • 2016-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多