thomasvargiu / laminas-messenger
Factories to use the Symfony Messenger in Laminas and Mezzio applications
Installs: 16 915
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^8.0
- laminas/laminas-servicemanager: ^3.11.1 || ^4.0
- psr/container: ^1.1 || ^2.0
- symfony/console: ^5.4 || ^6.0
- symfony/event-dispatcher: ^5.4 || ^6.0 || ^7.0
- symfony/messenger: ^5.4.45
Requires (Dev)
- doctrine/dbal: ^2.13.9 || ^3.0 || ^4.0
- doctrine/orm: ^2.20.1 || ^3.0
- doctrine/persistence: ^3.4 || ^4.0
- facile-it/facile-coding-standard: ^1.3
- friendsofphp/php-cs-fixer: ^3.68.1
- laminas/laminas-config-aggregator: ^1.4
- phpspec/prophecy-phpunit: ^2.3.0
- phpunit/phpunit: ^9.6.22
- psalm/plugin-phpunit: ^0.19.0
- psr/cache: ^1.0.1 || ^2.0 || ^3.0
- psr/log: ^1.1.4 || ^2.0 || ^3.0
- symfony/amqp-messenger: ^5.4 || ^6.0 || ^7.0
- symfony/contracts: ^2.5.5 || ^3.0
- symfony/doctrine-messenger: ^v5.4.45 || ^6.0
- symfony/redis-messenger: ^5.4 || ^6.0 || ^7.0
- vimeo/psalm: ^5.26.1 || ^6.0
Suggests
- doctrine/dbal: To use doctrine transport
- doctrine/orm: To use doctrine ORM middlewares
- psr/cache-implementation: To use stop workers command
This package is auto-updated.
Last update: 2025-01-28 23:15:53 UTC
README
Factories to use the Symfony Messenger in Laminas and Mezzio applications (ex zend-framework and zend-expressive)
Usage
You need to add console commands to your application. The following command services are already configured for you:
Symfony\Component\Messenger\Command\ConsumeMessagesCommand
Symfony\Component\Messenger\Command\SetupTransportsCommand
Symfony\Component\Messenger\Command\FailedMessagesRemoveCommand
Symfony\Component\Messenger\Command\FailedMessagesRetryCommand
Symfony\Component\Messenger\Command\FailedMessagesShowCommand
Symfony\Component\Messenger\Command\StopWorkersCommand
(see note below)
To use the Symfony\Component\Messenger\Command\StopWorkersCommand
command you should set a CacheItemPoolInterface
implementation (see below).
A default message bus is already configured for you with the following service name: messenger.bus.default
.
You can read the Symfony documentation to know
how to use it.
Configuration
This is an example configuration:
use TMV\Laminas\Messenger\Factory; use Symfony\Component\Messenger; return [ 'dependencies' => [ 'factories' => [ 'messenger.bus.foo' => [Factory\MessageBusFactory::class, 'messenger.bus.foo'], // the name must be the same as the bus configuration key 'messenger.transport.async' => [Factory\Transport\TransportFactory::class, 'messenger.transport.async'], // the name must be the same as the transport configuration key ], ], 'messenger' => [ 'failure_transport' => null, // your failure transport service name (optional) 'logger' => null, // your custom logger service name (optional) 'default_serializer' => SFMessenger\Transport\Serialization\PhpSerializer::class, // default messenger serializer, it should be a service name 'cache_pool_for_restart_signal' => null, // CacheItemPoolInterface service name implementation if you want to use stop workers command 'transport_factories' => [ // here you can add your custom transport factories services ], 'subscribers' => [], // Subscribers (service name) to use with the default event dispatcher factory 'buses' => [ 'messenger.bus.foo' => [ // bus service name, it should be registered as a service with the same name 'default_middleware' => true, // if you want to include default middleware (default: true) 'middleware' => [ // your custom middleware service names My\FooMiddleware::class, ], 'allow_no_handler' => false, // allow no handlers (default: false) 'handlers' => [ // your handlers My\FooMessageType::class => [ My\FooMessageHandler::class, ], ], 'routes' => [ My\FooMessageType::class => ['messenger.transport.async'], // route message types to this transport ], ], ], 'transports' => [ 'messenger.transport.async' => [ 'dsn' => 'amqp://guest:guest@rabbitmq:5672', 'serializer' => Messenger\Transport\Serialization\PhpSerializer::class, // custom serializer service 'options' => [ 'exchange' => [ 'name' => 'messenger_events', ], 'queues' => [ 'messenger_events' => [], ], ], 'retry_strategy' => [ 'max_retries' => 3, 'delay' => 1000, 'multiplier' => 2, 'max_delay' => 0, ], ], ], ], ];
Doctrine Helpers
Middlewares
There are some middleware available for Doctrine:
TMV\Laminas\Messenger\Middleware\DoctrineCloseConnectionMiddleware
Close connection on every message consumed by the worker.
TMV\Laminas\Messenger\Middleware\DoctrinePingConnectionMiddleware
Before to handle a message on worker, ping to check whether the connection is open or try to reconnect it.
TMV\Laminas\Messenger\Middleware\DoctrineTransactionMiddleware
For every message, wrap the message handler with a transaction.
Subscribers
TMV\Laminas\Messenger\Subscriber\DoctrineClearEntityManagerWorkerSubscriber
This subscriber clear the EntityManager after a message is handled in a worker.