send complex values

This commit is contained in:
2026-02-25 00:38:35 +01:00
parent 25e8c88ce0
commit 5bdf915c4a
8 changed files with 171 additions and 36 deletions
+24 -1
View File
@@ -1,17 +1,40 @@
use core::ops::Deref;
use futures::StreamExt;
use postcard::from_bytes;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct InnerStruct<'a> {
str: &'a str,
}
#[derive(Serialize, Deserialize, Debug)]
struct MyStruct<'a> {
len: usize,
str: &'a str,
inner: InnerStruct<'a>,
}
#[tokio::main]
async fn main() {
let nats_client = async_nats::connect("nats://localhost:4222")
.await
.expect("Error creating nats client");
let mut subscriber = nats_client
.queue_subscribe("jobs", "download".to_string())
.queue_subscribe("corro-dj.*", "download".to_string())
.await
.unwrap();
// Receive and process messages
while let Some(message) = subscriber.next().await {
println!("{:?}", message.payload);
let result: MyStruct = from_bytes(message.payload.deref()).unwrap();
println!("{:?}", result);
println!("Received message {:?}", message);
}
}