Skip to main content

messages

messages returns every message published to the destination, with its name, headers and payload, for checks of your own.

The slice is in publish order, one RawMessage per publish. Each message gives its destination through name(), its headers through headers() and its bytes through payload(). The built-in assertions, such as with_header, read only the latest message; messages is the way to check every one. decoded returns every payload as a value. The slice borrows the record, so bind the record to a variable first.

Example​

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

let tickets = broker.published::<Ticket>("tickets");
assert_eq!(tickets.messages().len(), 2);
for ticket in tickets.messages() {
assert_eq!(ticket.name(), "tickets");
assert_eq!(ticket.headers().get("x-order"), Some(&b"7"[..]));
}
Ok(())
}