use std::io;
use std::time::Duration;
use ruststream::runtime::{App, AppInfo, RustStream};
use ruststream::{IncomingMessage, OutgoingMessage, RequestReply};
use ruststream_nats::{NatsBroker, NatsPublish};
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("requester", "0.1.0")).with_broker(
NatsBroker::new("nats://localhost:4222"),
|b| {
b.after_startup(NatsPublish, async move |requester| -> io::Result<()> {
let reply = requester
.request(
OutgoingMessage::new("questions", b"what is the answer?"),
Duration::from_secs(2),
)
.await
.map_err(io::Error::other)?;
println!("reply: {}", String::from_utf8_lossy(reply.payload()));
Ok(())
});
},
)
}