How to inject a producer as a service into a RabbitMQBundle consumer?
You can inject the rabbitmq producer in your consumer and use it as usual. As example you can change the consumer service configuration as follow (see the last arguments):
my_own_service: class: MyOwnBundleBundle\Consumers\MyOwnConsumer arguments: ["@logger", "@doctrine_mongodb", "%variable1%", "%variable2%", "@old_sound_rabbit_mq.another_producer"] tags: - { name: monolog.logger, channel: my_own_channel }
and change the contructor of your service to accept the new parameter:
protected $producer;public function __construct($logger, $doctrine, $var1,$var2, $producer){ ... $this->producer=$producer;}
And so use it as :
public function execute(AMQPMessage $msg) { .... $mesassage = .... $this->producer-> publish($message); }
Hope this help