您可以在您的消费者中注入rabbitmq生成器并照常使用它。例如,您可以更改消费者服务配置,如下所示(请参阅最后一个参数):
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 }
并更改服务的构造函数以接受新参数:
protected $producer; public function __construct($logger, $doctrine, $var1,$var2, $producer) { ... $this->producer=$producer; }
因此,请将其用作:
public function execute(AMQPMessage $msg) { .... $mesassage = .... $this->producer-> publish($message); }
希望这有帮助