Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Custom middleware

Middleware wraps the message flow between an input and an output — retries, dedup, transforms, and so on. When the built-in set doesn’t cover your need, register your own and select it from config by name.

Config

Middleware attaches to a route side, so the list goes under input: or output::

output:
  mongodb:
    url: "mongodb://localhost:27017"
  middlewares:
    - custom:
        name: "my_enricher"
        config: { lookup_url: "http://enrich.internal" }
FieldTypeRequired
namestringyes — matches the registered factory
configany JSONyes — passed through to your factory

Implementing it

Implement the CustomMiddlewareFactory trait and register it before starting routes. It exposes apply_consumer and/or apply_publisher — each defaults to pass-through, so you only implement the side you need. The consumer and publisher sides are separate because middleware wraps a MessageConsumer on the way in and a MessagePublisher on the way out; wrap order matters (see the architecture doc).

See also