cptburke / symfony-messenger-application-bundle
bundle to use symfony-messenger-application (query, command, event, ...) in your symfony application
Installs: 75
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/cptburke/symfony-messenger-application-bundle
Requires
- php: >=8.0
- cptburke/symfony-messenger-application: ^0.1.2
- symfony/config: 6.4.*
- symfony/dependency-injection: 6.4.*
- symfony/http-kernel: 6.4.*
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/test-pack: ^1.0
This package is not auto-updated.
Last update: 2025-10-13 20:24:01 UTC
README
bundle to use symfony-messenger-application (query, command, event, ...) in your symfony application
Installation
composer require cptburke/symfony-messenger-application-bundle
Configuration
This bundle tags classes that implement one of these interfaces via autoconfiguration:
CptBurke\Application\Query\QueryHandlergets tagged withmessenger_application.query.handlerCptBurke\Application\Command\CommandHandlergets tagged withmessenger_application.command.handlerCptBurke\Application\Domain\DomainEventSubscribergets tagged withmessenger_application.domain_event.subscriberCptBurke\Application\Event\ApplicationEventSubscribergets tagged withmessenger_application.application_event.subscriber
It also pre-configures several buses:
messenger_application.query.busQuery bus with autoconfigured mapping for handlers that implementCptBurke\Application\Query\QueryHandlermessenger_application.domain_event.busDomain event bus with autoconfigured mapping for subscribers that implementCptBurke\Application\Domain\DomainEventSubscribermessenger_application.command.busCommand bus that takes anSymfony\Messenger\MessageBusInterfacewhich can be configured throughservices.yaml,messenger.yamlmessenger_application.application_event.busApplication event bus that takes anSymfony\Messenger\MessageBusInterfacewhich can be configured throughservices.yaml,messenger.yaml
To use async transport for command or application event buses, you can leverage the SendMessageMiddleware configured by the transport config
messenger_application.transport.senderstakes a map of message classes to a list of transports
config/packages/messenger_application.yaml
The minimal configuration contains services for the command bus and the application event bus (if you want to use them in your application).
config/services.yaml
#... command.handler_middleware: factory: [CptBurke\Application\SymfonyMessengerBundle\Factory\HandlerMiddlewareStackFactory, createCallables] arguments: - !tagged_iterator messenger_application.command.handler #...
config/packages/messenger.yaml
buses: #... command.bus: default_middleware: false middleware: - doctrine_transaction - messenger_application.transport.senders - command.handler_middleware
messenger_application: # service id of the configured symfony message bus command_bus: 'command.bus' # service id of the configured symfony message bus application_event_bus: 'app.async_bus' query_bus: # middleware before query gets handled before_handle: - Acme\Middleware\SomeMiddleware # middleware after query was handled after_handle: [] domain_event_bus: before_handle: - 'app.middleware.some_middleware' after_handle: - Acme\Middleware\LoggerMiddleware # SomeCommand would be sent to DoctrineTransport service transport: senders: Acme\Command\SomeCommand: ['DoctrineTransport']
Usage
Example
<?php use CptBurke\Application\Query\QueryBus; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class SampleController extends AbstractController { public function sampleAction(QueryBus $bus) { $data = $bus->ask(new GetDataQuery()); // or $data = $this->get(QueryBus::class)->ask(new GetDataQuery()); // or $data = $this->get('messenger_application.query.bus')->ask(new GetDataQuery()); return $this->json($data); }