【发布时间】:2015-03-07 19:15:17
【问题描述】:
我在我的 sf2 项目中安装了https://github.com/videlalvaro/RabbitMqBundle,配置如下:
old_sound_rabbit_mq:
connections:
default:
host: 'localhost'
port: 5672
user: 'guest'
password: 'guest'
vhost: '/'
lazy: false
producers:
processing:
connection: default
exchange_options: { name: 'processing', type: direct }
class: Assignment\Bundle\MainBundle\RabbitMq\Producer\ProcessingProducer
服务配置:
processing_producer:
class: Assignment\Bundle\MainBundle\RabbitMq\Producer\ProcessingProducer
arguments: []
制作者来源:
class ProcessingProducer extends Producer
{
public function __construct()
{
parent::setContentType("application/json");
}
/**
* @param string $msgBody
* @param string $routingKey
* @param array $additionalProperties
*/
public function publish($msgBody, $routingKey = '', $additionalProperties = array())
{
$msgBody = json_encode($msgBody);
parent::publish($msgBody, $routingKey, $additionalProperties);
}
}
在控制器中我尝试做一个测试发布:
public function indexAction()
{
$this->get('old_sound_rabbit_mq.processing_producer')->publish(array('a' => 'b'));
return $this->render('::Default/index.html.twig');
}
结果是:Error: Call to a member function channel() on a non-object
[1] Symfony\Component\Debug\Exception\FatalErrorException: Error: Call to a member function channel() on a non-object
at n/a
in /var/www/vendor/oldsound/rabbitmq-bundle/OldSound/RabbitMqBundle/RabbitMq/BaseAmqp.php line 75
at OldSound\RabbitMqBundle\RabbitMq\BaseAmqp->getChannel()
in /var/www/vendor/oldsound/rabbitmq-bundle/OldSound/RabbitMqBundle/RabbitMq/BaseAmqp.php line 129
at OldSound\RabbitMqBundle\RabbitMq\BaseAmqp->exchangeDeclare()
in /var/www/vendor/oldsound/rabbitmq-bundle/OldSound/RabbitMqBundle/RabbitMq/BaseAmqp.php line 167
at OldSound\RabbitMqBundle\RabbitMq\BaseAmqp->setupFabric()
in /var/www/vendor/oldsound/rabbitmq-bundle/OldSound/RabbitMqBundle/RabbitMq/Producer.php line 45
at OldSound\RabbitMqBundle\RabbitMq\Producer->publish('msgBody' => '', 'routingKey' => '', 'additionalProperties' => '')
in /var/www/src/Assignment/Bundle/MainBundle/RabbitMq/Producer/ProcessingProducer.php line 26
at Assignment\Bundle\MainBundle\RabbitMq\Producer\ProcessingProducer->publish('msgBody' => '', 'routingKey' => '', 'additionalProperties' => '')
in /var/www/src/Assignment/Bundle/MainBundle/Controller/DefaultController.php line 15
at Assignment\Bundle\MainBundle\Controller\DefaultController->indexAction()
in /var/www/app/bootstrap.php.cache line 3022
at call_user_func_array('', '')
in /var/www/app/bootstrap.php.cache line 3022
at Symfony\Component\HttpKernel\HttpKernel->handleRaw('request' => '', 'type' => '')
in /var/www/app/bootstrap.php.cache line 2984
at Symfony\Component\HttpKernel\HttpKernel->handle('request' => '', 'type' => '', 'catch' => '')
in /var/www/app/bootstrap.php.cache line 3133
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle('request' => '', 'type' => '', 'catch' => '')
in /var/www/app/bootstrap.php.cache line 2377
at Symfony\Component\HttpKernel\Kernel->handle('request' => '', 'type' => '', 'catch' => '')
in /var/www/web/app_dev.php line 28
at {main}()
in /var/www/web/app_dev.php line 0
【问题讨论】: