happyr / bref-messenger-failure-strategies
Make sure you can use Bref Symfony Messenger failure strategies
Fund package maintenance!
Nyholm
Installs: 134 453
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.3
- bref/symfony-messenger: ^0.3 || ^0.4 || ^0.5 || ^1.0
- symfony/messenger: ^4.4 || ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^8.5.31
- symfony/event-dispatcher-contracts: ^2.0
- symfony/polyfill-php80: ^1.17
- symfony/validator: ^5.0 || ^6.0 || ^7.0
README
So you have fallen in love with Bref and you really want to use Symfony's excellent Messenger component. You've probably also installed the Bref Symfony Messenger bundle that allows you to publish messages on SQS and SNS etc. But you are missing something... You want to be able to use Symfony Messenger retry strategies, right?
This is the package for you!
Install
composer require happyr/bref-messenger-failure-strategies
Now you have a class called Happyr\BrefMessenger\SymfonyBusDriver
that implements
Bref\Symfony\Messenger\Service\BusDriver
. Feel free to configure your consumers with this
new class.
Example
On each consumer you can choose to let Symfony handle failures as described in the documentation.
# config/packages/messenger.yaml framework: messenger: failure_transport: failed transports: failed: 'doctrine://default?queue_name=failed' workqueue: dsn: 'https://sqs.us-east-1.amazonaws.com/123456789/my-queue' retry_strategy: max_retries: 3 # milliseconds delay delay: 1000 multiplier: 2 max_delay: 60 services: Happyr\BrefMessenger\ExceptionLogger: autowire: true autoconfigure: true Happyr\BrefMessenger\SymfonyBusDriver: autowire: true Bref\Symfony\Messenger\Service\Sqs\SqsConsumer: arguments: - '@Happyr\BrefMessenger\SymfonyBusDriver' - '@messenger.routable_message_bus' - '@Symfony\Component\Messenger\Transport\Serialization\SerializerInterface' - 'my_sqs' # Same as transport name # ...
The delay is only supported on SQS "normal queue". If you are using SNS or SQS FIFO you should use the failure queue directly.
# config/packages/messenger.yaml framework: messenger: failure_transport: failed transports: failed: 'doctrine://default?queue_name=failed' workqueue: dsn: 'sns://arn:aws:sns:us-east-1:1234567890:foobar' retry_strategy: max_retries: 0 services: # ...
Make sure you re-run the failure queue time to time. The following config will run a script for 5 seconds every 30 minutes. It will run for 5 seconds even though no messages has failed.
# serverless.yml functions: website: # ... consumer: # ... console: handler: bin/console Timeout: 120 # in seconds layers: - ${bref:layer.php-74} - ${bref:layer.console} events: - schedule: rate: rate(30 minutes) input: cli: messenger:consume failed --time-limit=5 --limit=50