/symfony-skills:messenger-asyncfrom symfony-skills
Implements async processing, CQRS, and event-driven flows in Symfony using the Messenger component, covering message/handler pairs, transports, routing, retries, failure queues, and the outbox pattern.
Ships in symfony-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A message is a plain, immutable DTO. A handler is a class with #[AsMessageHandler] and an __invoke() typed to the message. One handler per command.
// Command message — immutable intent
final readonly class PlaceOrder
{
/** @param array<int, array{productId: string, quantity: int}> $items */
public function __construct(
public string $customerEmail,
public array $items,
) {}
}
// Handler
#[AsMessageHandler]
final class PlaceOrderHandler
{
public function __construct(private readonly OrderService $orders) {}
public function __invoke(PlaceOrder $command): void
{
$this->orders->placeOrder($command);
}
}
// Dispatch from a controller/service
$this->bus->dispatch(new PlaceOrder($request->customerEmail, $request->items));
# config/packages/messenger.yaml
framework:
messenger:
default_bus: command.bus
buses:
command.bus: # one handler, returns void/id
middleware: [validation, doctrine_transaction]
query.bus: # one handler, returns a read model
event.bus: # zero-or-many handlers, fan-out
default_middleware: allow_no_handlers
PlaceOrder).GetOrderSummary).OrderPlaced).Sync by default; route the slow/external work to an async transport.
framework:
messenger:
transports:
async:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%' # doctrine:// , amqp:// , redis://
retry_strategy:
max_retries: 3
delay: 1000
multiplier: 2 # exponential backoff
failed: 'doctrine://default?queue_name=failed'
failure_transport: failed
routing:
App\Message\Command\PlaceOrder: async
App\Message\Event\OrderPlaced: async
Run a worker to consume async messages:
php bin/console messenger:consume async --time-limit=3600 --memory-limit=256M
In production, supervise the worker (systemd / Supervisor) and recycle it (--time-limit) to avoid leaks.
failed transport instead of being lost.php bin/console messenger:failed:show # inspect
php bin/console messenger:failed:retry # replay after a fix
php bin/console messenger:failed:remove <id> # discard
Throw UnrecoverableMessageHandlingException to skip retries for errors that will never succeed (bad payload, business rule violation).
Async messages can be delivered more than once (retry, at-least-once transports). Handlers must be idempotent — process by a natural key and no-op if already done.
public function __invoke(ChargePayment $message): void
{
if ($this->payments->existsByIdempotencyKey($message->idempotencyKey)) {
return; // already processed — safe to receive twice
}
$this->gateway->charge($message);
}
Dispatching a message after flush() can lose it if the process dies in between; dispatching before can emit an event for a transaction that then rolls back. The Doctrine transport with the DispatchAfterCurrentBusMiddleware (built in) handles the in-bus case; for cross-process reliability, persist the message in the same transaction (outbox) and let a relay/worker publish it.
// Dispatch within the handler's transaction; the transport row commits atomically.
$this->bus->dispatch(new OrderPlaced($order->getId()), [new DispatchAfterCurrentBusStamp()]);
layered-architecture).failure_transport — failed messages vanish; add the failed transport.UnrecoverableMessageHandlingException for non-retryable errors.flush() (or after, unguarded) — use DispatchAfterCurrentBusStamp / outbox for atomicity.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
symfony-messenger, async-processing, cqrs, event-driven, message-bus, queue
npx claudepluginhub fatonh/symfony-skills --plugin symfony-skills17 skills in this plugin
/api-platform-resourcesUse when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.
/bundle-organizationUse when structuring a Symfony project's src/ directory, organizing code into modules, configuring services, or deciding where a class belongs. Covers the modular monolith layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).
/console-commandsUse when creating or refactoring Symfony console commands — never extends Command. On Symfony 8.1+ put #[AsCommand] on a method of a service class (even for a single command); on 7.x use the invokable attribute class. Also covers typed CLI inputs via value resolvers and #[MapInput] DTOs. Use when the task mentions console command, #[AsCommand], bin/console, #[Argument], #[Option], or a CLI task.
Other plugins' skills for the same job