ruststream-lapin 0.5.2

RabbitMQ / AMQP 0.9.1 broker implementation for the RustStream messaging framework, backed by lapin.
Documentation
//! In-process unit-testing: the same handlers and descriptors, no `RabbitMQ` server.
//!
//! The `testing` feature ships `LapinTestBroker`, an in-process stand-in for `RabbitMQ`. Build
//! the app around it exactly as in production, drive publishes with `TestApp::publish` (which
//! waits for the handlers to settle), and assert on what they did.
//!
//! ```text
//! cargo run --example lapin_testing --features testing
//! ```

use ruststream::runtime::{AppInfo, HandlerResult, RustStream};
use ruststream::subscriber;
use ruststream::testing::TestApp;
use ruststream_lapin::RabbitQueue;
use ruststream_lapin::testing::LapinTestBroker;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Payment {
    amount: u64,
}

// --8<-- [start:handler]
#[subscriber(RabbitQueue::new("payments"))]
async fn accept(payment: &Payment) -> HandlerResult {
    if payment.amount == 0 {
        return HandlerResult::drop();
    }
    HandlerResult::Ack
}
// --8<-- [end:handler]

#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
async fn main() {
    // --8<-- [start:testapp]
    let app = RustStream::new(AppInfo::new("payments", "0.1.0")).with_broker(
        LapinTestBroker::new(),
        |b| {
            b.include(accept);
        },
    );
    let tb = TestApp::start(app).await.expect("start");

    tb.broker::<LapinTestBroker>()
        .publish("payments", &Payment { amount: 100 })
        .await
        .expect("publish drives the handler to quiescence");

    tb.broker::<LapinTestBroker>()
        .subscriber("payments")
        .assert_called_once()
        .with(&Payment { amount: 100 })
        .settled(HandlerResult::Ack);

    tb.shutdown().await.expect("shutdown");
    // --8<-- [end:testapp]

    println!("all in-process checks passed");
}