Есть проект на symfony v6.2 с установленным пакетом php-amqplib/rabbitmq-bundle. В нём настроен один Producer (PushToQueue) и один Consumer (Send). Когда я пытаюсь добавить ещё одну пару Producer(PushToQueueTest)-Consumer(SendTest) и использовать новый Producer(PushToQueueTest) в зависимостях любого класса, происходит ошибка автовнедрения зависимостей:
Cannot autowire service "App\Email\Infrastructure\Service\PushToQueueTest": argument "$conn" of method "OldSound\RabbitMqBundle\RabbitMq\BaseAmqp::__construct()" references class "PhpAmqpLib\Connection\AbstractConnection" but no such service exists. You should maybe alias this class to the existing "old_sound_rabbit_mq.connection.default" service.
При попытке внедрить зависимость $conn через config/services.yaml таким образом
services:
_defaults:
autowire: true
autoconfigure: true
bind:
$conn: '@old_sound_rabbit_mq.connection.default'
я получаю новую проблему:
Warning: Undefined array key "name"
file: /app/vendor/php-amqplib/rabbitmq-bundle/RabbitMq/BaseAmqp.php,
line: 201
type: ErrorException
Подскажите, пожалуйста, что я делаю не так.
Ниже содержимое всех необходимых файлов.
config/packages/old_sound_rabbit_mq.yaml:
old_sound_rabbit_mq:
connections:
default:
host: 'rabbitmq'
port: '%env(resolve:RABBITMQ_DEFAULT_PORT)%'
user: '%env(resolve:RABBITMQ_DEFAULT_USER)%'
password: '%env(resolve:RABBITMQ_DEFAULT_PASS)%'
vhost: '/'
lazy: true
connection_timeout: 3
read_write_timeout: 3
keepalive: false
heartbeat: 0
use_socket: true
producers:
send_email:
class: App\Email\Infrastructure\Service\PushToQueue
connection: default
exchange_options: { name: 'send_email', type: direct }
send_email_test:
class: App\Email\Infrastructure\Service\PushToQueueTest
connection: default
exchange_options: { name: 'send_email_test', type: direct }
consumers:
send_email:
connection: default
exchange_options: { name: 'send_email', type: direct }
queue_options: { name: 'send_email' }
callback: App\Email\Application\Consumer\Send
send_email_test:
connection: default
exchange_options: { name: 'send_email_test', type: direct }
queue_options: { name: 'send_email_test' }
callback: App\Email\Application\Consumer\Send
PushToQueue:
<?php
namespace App\Email\Infrastructure\Service;
use App\Shared\Infrastructure\Service as SharedInfrastructureService;
class PushToQueue extends SharedInfrastructureService\BasePushToQueue
{
}
PushToQueueTest:
<?php
namespace App\Email\Infrastructure\Service;
use App\Shared\Infrastructure\Service as SharedInfrastructureService;
class PushToQueueTest extends SharedInfrastructureService\BasePushToQueue
{
}
Send:
<?php
namespace App\Email\Application\Consumer;
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
use PhpAmqpLib\Message\AMQPMessage;
use App\Email\Domain\Service as DomainService;
class Send implements ConsumerInterface
{
public function __construct(
readonly private DomainService\Send $sendService,
) {
}
public function execute(AMQPMessage $msg): int
{
$data = json_decode($msg->getBody(), true);
$status = $this->sendService->setData($data)->service();
return $status->value;
}
}
SendTest:
<?php
namespace App\Email\Application\Consumer;
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
use PhpAmqpLib\Message\AMQPMessage;
use App\Email\Domain\Service as DomainService;
class SendTest implements ConsumerInterface
{
public function __construct(
readonly private DomainService\Send $sendService,
) {
}
public function execute(AMQPMessage $msg): int
{
$data = json_decode($msg->getBody(), true);
$status = $this->sendService->setData($data)->service();
return $status->value;
}
}