diff --git a/example/rust/README.template.md b/example/rust/README.template.md index b4d83207..5a714bb8 100644 --- a/example/rust/README.template.md +++ b/example/rust/README.template.md @@ -35,4 +35,6 @@ MOMENTO_API_KEY= cargo run --bin=topics Example Code: [topics.rs](src/bin/topics.rs) +Note: to see a non-null `publisher_id` on a received [`SubscriptionValue`](https://docs.rs/momento/0.46.1/momento/topics/struct.SubscriptionValue.html), you'll need to set the optional `token_id` argument when programmatically creating a [disposable token](https://docs.momentohq.com/cache/develop/api-reference/auth#generatedisposabletoken). + {{ ossFooter }} diff --git a/example/rust/src/bin/topics.rs b/example/rust/src/bin/topics.rs index 3755f8b6..ef6d1d1a 100644 --- a/example/rust/src/bin/topics.rs +++ b/example/rust/src/bin/topics.rs @@ -16,9 +16,15 @@ async fn main() -> MomentoResult<()> { // call `abort()` on the task handle after messages are published. let mut subscription1 = topic_client.subscribe("cache", "my-topic").await?; let subscriber_handle1 = tokio::spawn(async move { - println!("Subscriber should keep receiving until task is aborted"); + println!("\n Subscriber [1] should keep receiving until task is aborted"); while let Some(message) = subscription1.next().await { - println!("[1] Received message: {:?}", message); + println!( + "[1] Received message: \n\tKind: {:?} \n\tSequence number: {:?} \n\tSequence page: {:?} \n\tPublisher ID: {:?}", + message.kind, + message.topic_sequence_number, + message.topic_sequence_page, + message.publisher_id + ); } }); @@ -38,10 +44,24 @@ async fn main() -> MomentoResult<()> { // let the task end after receiving 10 messages. let mut subscription2 = topic_client.subscribe("cache", "my-topic").await?; tokio::spawn(async move { - println!("Subscriber should receive 10 messages then exit"); + println!("\nSubscriber [2] should receive 10 messages then exit"); for _ in 0..10 { let message = subscription2.next().await; - println!("[2] Received message: {:?}", message); + // println!("[2] Received message: {:?}", message); + match message { + Some(message) => { + println!( + "[2] Received message: \n\tKind: {:?} \n\tSequence number: {:?} \n\tSequence page: {:?} \n\tPublisher ID: {:?}", + message.kind, + message.topic_sequence_number, + message.topic_sequence_page, + message.publisher_id + ); + } + None => { + println!("[2] Received None item from subscription"); + } + } } });