2012-02-07 72 views
1

我试图让RabbitMQ与Yii控制台一起工作来发送交易电子邮件,但我遇到了让PHP-AMQPLib库在Yii中工作的问题。我的代码如下:RabbitMQ和Yii控制台回调错误

<?php 
class RabbitMqCommand extends CConsoleCommand { 

    public function actionSendMail() { 
     require_once ('/htdocs/code/wwwroot/protected/components/php-amqplib/amqp.inc'); 

     $conn = new AMQPConnection ('localhost', 5672, 'guest', '123456', '/'); 
     $ch = $conn->channel(); 

     $ch->queue_declare ('msgs', false, true, false, false); 

     $ch->exchange_declare ('router', 'direct', false, true, false); 

     $ch->queue_bind ('msgs', 'router'); 

     $ch->basic_consume ('msgs', 'consumer', false, false, false, false, 'processMessage'); 

      // Loop as long as the channel has callbacks registered 
     while (count ($ch->callbacks)) { 
      $ch->wait(); 
     } 

     $ch->close(); 
     $conn->close(); 


    } 

    public function processMessage($msg) 
     { 
      //process and send email 
     } 

当我尝试在命令行中执行该代码如下:

php -q /htdocs/code/wwwroot/protected/yiic RabbitMQ SendMail 

我收到以下错误信息:

PHP Error[2]: call_user_func() expects parameter 1 to be a valid callback, function 'processMessage' not found or invalid function name 
   in file /htdocs/code/wwwroot/protected/components/php-amqplib/amqp.inc at line 1390 
#0 /htdocs/code/wwwroot/protected/components/php-amqplib/amqp.inc(1390): call_user_func() 
#1 unknown(0): AMQPChannel->basic_deliver() 
#2 /htdocs/code/wwwroot/protected/components/php-amqplib/amqp.inc(167): call_user_func() 
#3 /htdocs/code/wwwroot/protected/components/php-amqplib/amqp.inc(275): AMQPChannel->dispatch() 
#4 /htdocs/code/wwwroot/protected/commands/RabbitMqCommand.php(29): AMQPChannel->wait() 
#5 unknown(0): RabbitMqCommand->actionSendMail() 
#6 /htdocs/code/framework/console/CConsoleCommand.php(135): ReflectionMethod->invokeArgs() 
#7 /htdocs/code/framework/console/CConsoleCommandRunner.php(63): RabbitMqCommand->run() 
#8 /htdocs/code/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run() 
#9 /htdocs/code/framework/base/CApplication.php(158): CConsoleApplication->processRequest() 
#10 /htdocs/code/framework/yiic.php(33): CConsoleApplication->run() 
#11 /htdocs/code/wwwroot/protected/yiic.php(7): require_once() 
#12 /htdocs/code/wwwroot/protected/yiic(4): require_once() 

任何想法我可能做错了?

回答