我有一個python應用程序使用pika庫將消息推入rabbitMQ隊列。RabbitMQ - PHP/Python的消費者問題
message='hola'
credentials = pika.PlainCredentials('guest', 'guest')
connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='myqueue')
channel.basic_publish(exchange='',routing_key='myqueue',body=message)
connection.close()
這是行得通的。
我需要在php應用程序中使用這些消息。我想這是在這個頁面中AQMP例子中提到 - http://www.php.net/manual/en/class.amqpqueue.php(檢查功能reciever)
$cnn = new AMQPConnection((array("host"=>"ec2-xxx-xx-xx-xxx.ap-southeast-1.compute.amazonaws.com","login"=>"guest", "password"=>"guest")));
if ($cnn->connect()) {
echo "Established a connection to the broker";
}
else {
echo "Cannot connect to the broker";
}
$queue = new AMQPQueue($cnn);
$queue->declare('myqueue');
$queue->bind('', 'myqueue');
$msg=$queue->get(AMQP_AUTOACK);
echo $msg->getBody();
拋出該異常 -
Fatal error: Uncaught exception 'Exception' with message 'Error parsing parameters.' in /home/webroot/amqptest.php:12 Stack trace: #0 /home/webroot/amqptest.php(12): AMQPQueue->declare('myqueue') #1 {main} thrown in /home/webroot/amqptest.php on line 12
什麼時候出現錯誤?當你連接的時候嗎?或者在你正在消費的部分? –