use ruststream::memory::{MemoryBroker, MemoryPublish};
use ruststream::runtime::{AppInfo, ForReply, Names, Outgoing as OutgoingMessage, PublishContext, PublishTransform, Reply, RustStream};
use ruststream::{Outgoing, subscriber};
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
struct Order {
id: u32,
}
#[derive(Serialize, Outgoing)]
#[outgoing(name = "receipts")]
struct Receipt {
id: u32,
}
struct ReplyTo;
impl<C, Options> PublishTransform<ForReply<C>, Options> for ReplyTo {
type Destination = Names;
fn apply(
&self,
out: &mut OutgoingMessage<'_>,
_options: &mut Option<Options>,
cx: &PublishContext<'_, C>,
) {
out.set_name(cx.name().to_owned());
}
}
#[subscriber("orders", reply)]
async fn confirm(order: &Order) -> Receipt {
Receipt { id: order.id }
}
fn main() {
RustStream::new(AppInfo::new("app", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
b.include(confirm).out(Reply, MemoryPublish).transform(ReplyTo);
});
}