我在pecl 1.0.3中使用amqp擴展,使用2.7.1 rabbitmq編譯。PHP AMQP消費者:服務器通道錯誤:404,消息:NOT_FOUND
我試圖得到一個基本的生產者/消費者例子的工作,但我不斷收到錯誤。在這個擴展中有很少的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
//...
}
Th EN發送它:
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/en/amqp.examples.php#109024
你是對的,謝謝。我最初使用的是一個php庫,而不是本機擴展,默認情況下,如果該庫沒有被聲明,則該庫創建隊列。 – Jamescowhen 2012-07-20 03:48:29