Symfony. Message of type "Query" was handled multiple times. Only one handler is expected when using

I trying to implement query.bus to my Symfony project:

     $data = new CreateClinicCommand(
            'Clinic one',
            '7729695811',
            '127521',
            'Moscow',
            'Moscow',
            'Some street',
            ['34524352352345','34524352352345']
        );
       $this->commandBus->dispatch($data);
       $clinic = $this->queryBus->handle(new FindClinicByIdQuery('9284666c-e35c-4ea2-9f6a-d520383483ad'));
       echo $clinic->getName()->getName();
       echo $clinic->getAddress()->getFullAddress();

It works fine. But when I add new QueryHandler and Query I get an error:

Message of type "AppClinicApplicationQueryClinicFindByIdFindClinicByIdQuery" was handled multiple times. Only one handler is expected when using "AppClinicApplicationCQRSQueryMessageQueryBus::handle()", got 2: "AppClinicApplicationQueryClinicFindAllFindClinicsByCriteriaHandler::__invoke", "AppClinicApplicationQueryClinicFindByIdFindClinicByIdHandler::__invoke".

It appears when I just add FindClinicsByCriteriaQuery and FindClinicsByCriteriaHandler into folder.

My messenger.yml:

 messenger:
        # The bus that is going to be injected when injecting MessageBusInterface
        default_bus: command.bus
        buses:
            command.bus:
                middleware:
                    - doctrine_transaction
            query.bus:
                middleware:

            event.bus:
                default_middleware: allow_no_handlers
                middleware:

services.bus

_instanceof:
        AppClinicApplicationCQRSCommandCommandHandler:
          tags:
            - {name: messenger.message_handler, bus: command.bus}
        AppClinicApplicationCQRSQueryQueryHandler:
          tags:
          - {name: messenger.message_handler, bus: query.bus}

Class MessageQueryBus:

class MessageQueryBus implements QueryBus
{
    use HandleTrait {
        handle as handleQuery;
    }

    /**
     * @var MessageBusInterface
     */
    private $queryBus;

    public function __construct(MessageBusInterface $queryBus)
    {
        $this->messageBus = $queryBus;
    }

    public function handle(Query $query)
    {
       return $this->handleQuery($query);
    }
}

and my Handler:

class FindClinicsByCriteriaHandler implements QueryHandler
{


    public function __invoke(Query $query)
    {
        // TODO: Implement __invoke() method.
    }
}

I found this error in [HandleTrait][1]
but I don’t understand what is meaning

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *