Request / reply
mq-bridge supports request-response patterns for interactive services such as web
APIs. A client sends a request and waits for the matching response, while the bridge
keeps the correlation details away from your handler.
The response output is the most direct option and the safest one under concurrency:
the response stays in the same execution context as the request, so concurrent
requests do not share a reply queue or race on correlation IDs.
How it works
- An input endpoint that supports request-reply (like
http) receives a request. - The message passes through the route’s processing chain — this is where you attach a handler to process the request and generate a response payload.
- The final message is sent to the
output. - If the output is
response: {}, the bridge sends the message back to the original input source, which delivers it as the reply (e.g. the HTTP response body).
Not every backend can do request-reply. It is only supported/tested for endpoints that natively support or emulate it. SQLx, files, AWS, IBM MQ, and Sled do not support request-reply. Check the backend table in the engine README.
Example: MongoDB request/response
A sender writes a request document to MongoDB and waits for a reply. The bridge reads the document, runs the handler, and writes the result back to the reply collection:
mongo_responder:
input:
mongodb:
url: "mongodb://localhost:27017"
database: "app_db"
collection: "requests"
output:
# 'response' sends the processed message back to the reply collection
# (whatever reply_to the sender set).
response: {}
Attaching the handler (Rust)
The response output only echoes what the pipeline produced — you supply the logic by
attaching a handler to the route:
use mq_bridge::models::Handled;
use mq_bridge::CanonicalMessage;
let handler = |mut msg: CanonicalMessage| async move {
let request_body = String::from_utf8_lossy(&msg.payload);
let response_body = format!("Handled response for: {}", request_body);
msg.payload = response_body.into();
Ok(Handled::Publish(msg))
};
// load the route from YAML, then attach `handler` to its output and run it.
See Embed the library for the full load-and-run scaffolding, and
Core concepts for the handler model
(CommandHandler / EventHandler / TypeHandler).
See also
request/responsestructural endpoints — the reference definitions.- Engine README, Patterns: Request-Response — the authoritative write-up.