$npx -y skills add aligundogdu/symfony-hexagonal-skill --skill symfony-messenger-asyncSymfony Messenger async processing — message queues, retry strategies, failure transport, Symfony Scheduler, idempotency patterns, background jobs. Triggers on: messenger, async, queue, retry, scheduler, background job, worker, transport, message queue, cron, scheduled task
| 1 | # Symfony Messenger & Async Processing |
| 2 | |
| 3 | You are an expert in async message processing with Symfony Messenger within hexagonal architecture. |
| 4 | |
| 5 | ## When to Activate |
| 6 | |
| 7 | - User needs async processing or background jobs |
| 8 | - User asks about message queues or retry strategies |
| 9 | - User mentions cron jobs (redirect to Scheduler) |
| 10 | - User needs idempotency or failure handling |
| 11 | - User asks about Symfony Scheduler |
| 12 | |
| 13 | ## Core Principle: No Cron Jobs |
| 14 | |
| 15 | **Never use raw cron.** Always use: |
| 16 | - **Symfony Messenger** for async message processing |
| 17 | - **Symfony Scheduler** for recurring tasks |
| 18 | |
| 19 | ## Async Command Pattern |
| 20 | |
| 21 | ```php |
| 22 | // The command is the same — async is a routing concern, not a code concern |
| 23 | namespace App\Application\Report\Command; |
| 24 | |
| 25 | final readonly class GenerateReport |
| 26 | { |
| 27 | public function __construct( |
| 28 | public string $reportId, |
| 29 | public string $userId, |
| 30 | public string $type, |
| 31 | ) { |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | // Handler is identical to sync — the bus handles async dispatch |
| 36 | #[AsMessageHandler(bus: 'command.bus')] |
| 37 | final readonly class GenerateReportHandler |
| 38 | { |
| 39 | public function __invoke(GenerateReport $command): void |
| 40 | { |
| 41 | // Long-running operation |
| 42 | } |
| 43 | } |
| 44 | ``` |
| 45 | |
| 46 | ```yaml |
| 47 | # Route to async transport |
| 48 | framework: |
| 49 | messenger: |
| 50 | routing: |
| 51 | 'App\Application\Report\Command\GenerateReport': async |
| 52 | ``` |
| 53 | |
| 54 | ## Idempotency |
| 55 | |
| 56 | Every async handler MUST be idempotent — safe to retry: |
| 57 | |
| 58 | ```php |
| 59 | #[AsMessageHandler(bus: 'command.bus')] |
| 60 | final readonly class ProcessPaymentHandler |
| 61 | { |
| 62 | public function __construct( |
| 63 | private PaymentRepositoryInterface $paymentRepository, |
| 64 | private PaymentGatewayInterface $paymentGateway, |
| 65 | ) { |
| 66 | } |
| 67 | |
| 68 | public function __invoke(ProcessPayment $command): void |
| 69 | { |
| 70 | // Check if already processed (idempotency) |
| 71 | $existing = $this->paymentRepository->findByIdempotencyKey($command->idempotencyKey); |
| 72 | if ($existing !== null) { |
| 73 | return; // Already processed, skip |
| 74 | } |
| 75 | |
| 76 | // Process payment |
| 77 | $result = $this->paymentGateway->charge($command->customerId, $command->amount); |
| 78 | $this->paymentRepository->save($result); |
| 79 | } |
| 80 | } |
| 81 | ``` |
| 82 | |
| 83 | ## References |
| 84 | |
| 85 | See `references/` for detailed guides: |
| 86 | - `messenger-config.md` — Full Messenger YAML configuration |
| 87 | - `idempotency-patterns.md` — Idempotency key strategies |
| 88 | - `scheduler-patterns.md` — Symfony Scheduler setup and patterns |