Skip to main content

Replies

A reply reports $message.header#/reply-to as where its address is read, so a transform can answer each request where it asked.

A request on this broker sets the AMQP reply-to property, and a handler reads it as the reply-to header. A reply can follow it: a transform on out_reply that declares Destination = Names sets the reply's address from that header. The reply then has no fixed address, and the receive operation's reply says where a client reads it: $message.header#/reply-to. Both publish policies report that location.

The mount site still names a reply destination, such as reply("receipts"). It is the reply's declared channel, and a delivery the transform leaves alone, one without reply-to, is answered there.

Example​

The reply of receive_orders reports its address location as $message.header#/reply-to.

/// The receipt names no address of its own, so the transform may name one per delivery.
#[derive(Debug, Serialize, Outgoing)]
struct Receipt {
order_id: u64,
}

/// Answers where the request asked to be answered: the `reply-to` property, which a handler reads
/// as the `reply-to` header.
#[derive(Debug, Clone, Copy)]
struct ToReplyTo;

impl<C, Options> PublishTransform<ForReply<C>, Options> for ToReplyTo {
type Destination = Names;

fn apply(
&self,
out: &mut Outgoing<'_>,
_options: &mut Option<Options>,
cx: &PublishContext<'_, C>,
) {
if let Some(address) = cx.headers().get_str("reply-to") {
let address = address.to_owned();
out.set_name(address);
}
}
}