use busrt::ipc::{Client, Config};
use busrt::rpc::{Rpc, RpcClient};
use busrt::{empty_payload, QoS};
use serde::Deserialize;
use std::collections::BTreeMap;
#[derive(Deserialize)]
struct Amount {
value: u64,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let name = "test.client.123";
let target = "test.client.rpc";
let config = Config::new("/tmp/busrt.sock", name);
let client = Client::connect(&config).await?;
let rpc = RpcClient::new0(client);
rpc.call0(target, "test", empty_payload!(), QoS::Processed)
.await?;
let mut payload: BTreeMap<&str, u32> = <_>::default();
payload.insert("value", 10);
rpc.call(
target,
"add",
rmp_serde::to_vec_named(&payload)?.into(),
QoS::Processed,
)
.await?;
let result = rpc
.call(target, "get", empty_payload!(), QoS::Processed)
.await?;
let amount: Amount = rmp_serde::from_slice(result.payload())?;
println!("{}", amount.value);
Ok(())
}