|
| 1 | +# Messenger Configuration |
| 2 | + |
| 3 | +```php |
| 4 | +return [ |
| 5 | + 'symfony' => [ |
| 6 | + 'messenger' => [ |
| 7 | + 'transports' => [ |
| 8 | + 'redis_transport' => [ |
| 9 | + // specifies the Redis server and stream/key |
| 10 | + // messages is the main stream where new messages are initially stored |
| 11 | + 'dsn' => 'redis://127.0.0.1:6379/messages', |
| 12 | + // defines which serializer to use to encode/decode messages |
| 13 | + 'serializer' => SymfonySerializer::class, |
| 14 | + 'retry_strategy' => [ |
| 15 | + // maximum number of retry attempts before moving a message to the failure transport |
| 16 | + 'max_retries' => 3, |
| 17 | + // initial delay before retrying a failed message, in milliseconds |
| 18 | + 'delay' => 1000, |
| 19 | + // each retry’s delay is multiplied by this factor |
| 20 | + 'multiplier' => 2, |
| 21 | + // maximum delay allowed between retries, 0 means unlimited or default behavior |
| 22 | + 'max_delay' => 0, |
| 23 | + ], |
| 24 | + ], |
| 25 | + // defines a transport named failed, used to store messages that cannot be delivered after retries. |
| 26 | + 'failed' => [ |
| 27 | + // specifies the Redis server and stream/key |
| 28 | + 'dsn' => 'redis://127.0.0.1:6379/failed', |
| 29 | + // defines which serializer to use to encode/decode messages |
| 30 | + 'serializer' => SymfonySerializer::class, |
| 31 | + ], |
| 32 | + ], |
| 33 | + // tells Symfony Messenger to send messages that exceed retry limits to the failed transport |
| 34 | + 'failure_transport' => 'failed', |
| 35 | + ], |
| 36 | + ], |
| 37 | + 'dependencies' => [ |
| 38 | + 'factories'> [ |
| 39 | + 'redis_transport' => [TransportFactory::class, 'redis_transport'], |
| 40 | + 'failed' => [TransportFactory::class, 'failed'], |
| 41 | + SymfonySerializer::class => fn(ContainerInterface $container) => new PhpSerializer(), |
| 42 | + ], |
| 43 | + ], |
| 44 | +]; |
| 45 | +``` |
| 46 | + |
| 47 | +## Main queue stream (`messages`) |
| 48 | + |
| 49 | +`messages` stream is the main queue where all new messages are initially stored. The Messenger worker consume messages from this stream and attempt to process them according to the application logic. |
| 50 | + |
| 51 | +## Dead Letter Queue (DLQ) |
| 52 | + |
| 53 | +DLQ is a dedicated transport where messages are sent when they fail to be processed after a configured number of retries. Each transport can define a retry_strategy specifying the maximum number of retry attempts, delays between retries, and exponential backoff rules. When a message exceeds the allowed retries, it is automatically forwarded to the failure transport and stored in `failed` stream, ensuring that failed messages do not block the queue. |
0 commit comments