跳到主要内容
本页尚未翻译

下面显示的是英文原文。

out

out::<M>() opens the record of one Out slot: every message the handler sent through it, on whichever broker it went.

M is the slot's marker type, the one the handler names in Out<impl Publisher, M>, and it implements OutSlot. The record is attributed by slot, not by destination, so it shows which slot sent a message when two slots share a destination. published::<T>(name) is the record of one destination on one broker. Each entry keeps the destination name, the headers and the per-message settings of the publish, which with_options checks. The record is untyped: decoded_as::<U>() turns it into one that decodes to U. messages returns every entry for checks of your own. A publish made outside the handler task, such as a spawned task, is not attributed to the slot.

Example​

#[tokio::test]
async fn the_audit_slot_carried_the_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
tb.broker::<MemoryBroker>()
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;

let copies = tb.out::<Audit>().assert_called_once();
assert_eq!(copies.messages()[0].name(), "audit");
assert_eq!(copies.decoded_as::<Order>().decoded(), [Order { id: 7 }]);
Ok(())
}