Search code examples
symfonyrabbitmqamqp

Error when calling Rabbitmq consumer from command line


I am trying to setup a simple AMQP publisher/consumer using Symfony2.2 with RabbitMq bundle, I am following the documentation on the bundle page

The publisher works fine, I can see my messages on the web manager of rabbitMq. When I try to run a consumer using the command

php app/console rabbitmq:consumer my.api

I get the following error:

Call to undefined method My\ApiBundle\Service\ConsumerService::setRoutingKey() in /***/vendor/oldsound/rabbitmq-bundle/OldSound/RabbitMqBundle/Command/BaseConsumerCommand.php on line 91

My setup:

confi.yml

old_sound_rabbit_mq:
    connections:
        my.api:
        host:      %amqp_host%
        port:      %amqp_port%
        user:      %amqp_user%
        password:  %amqp_password%
        vhost:     %amqp_vhost%
    producers:
        my.api:
            connection: my.api
            exchange_options: {name: 'my.api', type: fanout}
    consumers:
        my.api:
            connection: my.api
            exchange_options: {name: 'my.api', type: fanout}
            queue_options:    {name: 'my.api'}
            callback:         my.api

My\ApiBundle\Service\ConsumerService.php

namespace My\ApiBundle\Service;

use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;

class ConsumerService implements ConsumerInterface
{
    public function execute(\PhpAmqpLib\Message\AMQPMessage $msg)
    {
        return false;
    }
}

My\ApiBundle\Resources\config\services.xml

<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
        <service id="old_sound_rabbit_mq.my.api_consumer" class="My\ApiBundle\Service\ConsumerService"></service>
    </services>
</container>

My question is: what is wrong with my config or my code?


Solution

  • There is no need to register your handler as a service - removing the My\ApiBundle\Resources\config\services.xml definition completely should solve the problem.