Configure the Symfony adapter

Last updated:

Two pieces: point a Messenger transport at the BabelQueue serializer, and map inbound URNs to your message classes.

Messenger transport

Set the transport’s serializer to babelqueue.messenger.serializer. Routing and retry stay exactly as Messenger defines them.

# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            babel:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'   # e.g. amqp:// or redis://
                serializer: 'babelqueue.messenger.serializer'
        routing:
            'App\Message\OrderCreated': babel
        buses:
            messenger.bus.default:
                middleware:
                    # Forward trace_id from a handled message to any it dispatches,
                    # so a chain of work stays in one trace.
                    - 'babelqueue.messenger.trace_middleware'

URN ↔ message-class map

To consume, the adapter needs to turn an inbound URN back into one of your message classes. Declare the mapping, plus the default queue written to the envelope’s meta.queue:

# config/packages/babelqueue.yaml
babelqueue:
    queue: 'orders'            # written to the envelope meta.queue
    messages:                  # urn => message class (needed to consume)
        'urn:babel:orders:created': 'App\Message\OrderCreated'

Producing only needs the message to declare its own URN (see Producing messages); the registry is what lets a consumer route an inbound envelope back to a class.

Idempotency

Consumer-side dedupe on meta.id is opt-in and configured under idempotency (see Idempotency (native middleware) for the bus wiring):

# config/packages/babelqueue.yaml
babelqueue:
    idempotency:
        enabled: true
        store: App\Babel\RedisIdempotencyStore   # an IdempotencyStore service id
        ttl: 3600
Key Default Meaning
queue 'default' Logical queue name written to the envelope meta.queue.
messages [] URN to message class map, used to decode inbound messages.
idempotency.enabled false Register the idempotency middleware. Behaviour is unchanged when off.
idempotency.store null Service id of a BabelQueue\Idempotency\IdempotencyStore (or ClaimingStore). null uses a bundled in-memory store, single-process and tests only.
idempotency.ttl 3600 In-flight claim TTL in seconds (the crash backstop); only honoured when the store is a ClaimingStore. Minimum 1.

The trace middleware

babelqueue.messenger.trace_middleware (added to the bus above) attaches the inbound trace_id to the message as a BabelTraceStamp and ensures any message a handler dispatches inherits that trace_id — so end-to-end tracing needs no manual plumbing. It is optional but recommended.

Next: Producing messages.