send complex values
This commit is contained in:
+24
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user