@routr/processor library as a processor. The difference is its job: a processor computes the route, while a middleware makes a small change or causes a side effect, then passes the message along. Typical uses are authentication, logging, tracing, request normalization, and driving RTPEngine. Routr ships two: SimpleAuth (pre-processor) and RTPRelay (post-processor).
Prerequisites
- Node.js and npm.
- A running Routr deployment that uses the Message Dispatcher. Middlewares only run through the Dispatcher; EdgePort never calls them directly.
How the Dispatcher calls middlewares
For each request, the Dispatcher:- Runs every middleware with
postProcessor: false, in the order listed. - Sends the result to the matching processor.
- Runs every middleware with
postProcessor: true, in the order listed, on the processor’s output.
message field of a middleware’s reply. If a middleware returns a SIP response (for example 401 Unauthorized), the Dispatcher skips the remaining middlewares in that phase and carries the response forward.
Use postProcessor: true when your middleware needs data the processor adds, such as the final Route headers or the SDP that the callee sends. RTPRelay runs post-processor for this reason.
Write the middleware
1
Install the library
Create a project and install
@routr/processor:2
Implement the handler
Create Always call
index.js. This middleware tags every INVITE with an X-Tenant header and passes all other messages through untouched. The default middleware port in Routr is 51903:index.js
res.send(req) for messages you don’t change. To reject a request, return a SIP response instead. SimpleAuth does this with CommonResponse.createUnauthorizedResponse() from @routr/common when the digest check fails.3
Run it
Start the middleware:
4
Register it in the Dispatcher
Add the middleware under On Kubernetes, add the entry under
spec.middlewares in dispatcher.yaml:dispatcher.yaml
dispatcher.middlewares in the Helm values (ref, serviceName, postProcessor); the chart points it at port 51903.Verify
Restart the Dispatcher and place a call. Capture the INVITE that leaves Routr (for example withsngrep) and confirm it carries X-Tenant: acme.
Pitfalls
- An unreachable middleware fails the request. If the Dispatcher can’t reach a middleware, it returns an error instead of skipping it.
- Keep it fast and stateless. Every listed middleware runs on every request.
- Filter early. Check the method or message type first and pass everything else through, as SimpleAuth does with its
METHODSlist.
Related
Build a processor
The full processor walkthrough and the
Response API.Alterations API
Helpers for editing SIP messages.
Message Dispatcher
Dispatcher configuration reference.
Message flow
Where middlewares sit in a request’s path.