Skip to content

Query Handlers

Query Handlers will handle a Query and return a result.


use SonsOfPHP\Component\Cqrs\Query\QueryMessageHandlerInterface;

final class ExampleQueryHandler implements QueryMessageHandlerInterface

Getting the Query to the Query Handler


The QueryMessageBus reqires the sonsofphp/cqrs-symfony package.

You can use Messenger to process queries. If you're using Messenger as a standalone component, inject your MessageBus object into the QueryMessageBus.


use SonsOfPHP\Bridge\Symfony\Cqrs\QueryMessageBus;

$queryBus = new QueryMessageBus($messageBus);

If using the Symfony Framework, it's even easier. You'll just need to update your services.yaml file.

    arguments: ['@query.bus']


You will need to configure Messenger to have multiple buses. query.bus is the name of the bus that was configured to process queries.

Using the QueryMessageBus is easy as well.


// Once you create a Query, it can just be handled.