sulu / messenger
This library provides the stamps, middlewares and the sulu message bus.
Installs: 21 789
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 5
Forks: 3
Open Issues: 0
Type:sulu-bundle
Requires
- php: 8.0.* || 8.1.* || 8.2.* || 8.3.*
- doctrine/dbal: ^2.13 || ^3.0
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.11
- psr/container: ^1.0 || ^2.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/doctrine-bridge: ^5.4 || ^6.0 || ^7.0
- symfony/framework-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/lock: ^5.4 || ^6.0 || ^7.0
- symfony/messenger: ^5.4 || ^6.0 || ^7.0
- symfony/service-contracts: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- coduo/php-matcher: ^6.0
- friendsofphp/php-cs-fixer: ^3.6
- handcraftedinthealps/code-coverage-checker: ^0.2.5
- jangregor/phpstan-prophecy: ^1.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4
- phpstan/phpstan-doctrine: ^1.2
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-symfony: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.0
- phpunit/phpunit: ^9.5
- qossmic/deptrac-shim: ^0.24.0 || ^1.0
- rector/rector: ^1.0
- schranz/test-generator: ^0.4
- symfony/browser-kit: ^5.4 || ^6.0 || ^7.0
- symfony/css-selector: ^5.4 || ^6.0 || ^7.0
- symfony/debug-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/dotenv: ^5.4 || ^6.0 || ^7.0
- symfony/error-handler: ^5.4 || ^6.0 || ^7.0
- symfony/phpunit-bridge: ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^5.4 || ^6.0 || ^7.0
- thecodingmachine/phpstan-strict-rules: ^1.0
README
This library provides the stamps and middlewares which configures the sulu message bus. It can be used independently in any symfony installation.
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
composer require sulu/messenger
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php return [ // ... Sulu\Messenger\Infrastructure\Symfony\HttpKernel\SuluMessengerBundle::class => ['all' => true], ];
Middlewares
UnpackExceptionMiddleware
The UnpackExceptionMiddleware
will unpack the HandlerFailedException
which
is created by the Symfony HandleMessageMiddleware
.
This way we make sure that the real exception is thrown out by this message
bus, and a controller can catch or convert it to a specific http status code.
This middleware is always activated in the sulu message bus.
LockMiddleware
The LockMiddleware
will allow to lock specific resources by a given key. This is commonly
used to prevent concurrent access to the same resource and avoid race conditions.
The locking can be activated and controlled via the LockStamp
which supports the same parameters
as the Symfony LockFactory
to create the Lock.
use Sulu\Messenger\Infrastructure\Symfony\Messenger\LockMiddleware\LockStamp; $this->handle(new Envelope(new YourMessage(), [new LockStamp('lock-key')])); # set ttl and autorelease $this->handle(new Envelope(new YourMessage(), [new LockStamp('lock-key', 300.0, true)])); # multiple locks possible all locks need to be acquired before processing the message $this->handle(new Envelope(new YourMessage(), [new LockStamp('lock-key-1'), new LockStamp('lock-key-2')]));
DoctrineFlushMiddleware
The DoctrineFlushMiddleware
is a Middleware which let us flush the Doctrine
EntityManager by an opt-in flag via the EnableFlushStamp
. It can be used this way:
use Sulu\Messenger\Infrastructure\Symfony\Messenger\FlushMiddleware\EnableFlushStamp; $this->handle(new Envelope(new YourMessage(), [new EnableFlushStamp()]));
This middleware is always activated in the sulu message bus.