Skip to content

register a handler for incoming messages on a push consumer #1176

Answered by Jarema
geraldmwangi asked this question in Q&A
Discussion options

You must be logged in to vote

Hey!

This is an idiomatic approach to handle streams of messages in Rust.
Why you want to avoid it?

If you want callabck behavior, you can use for_each (or evenfor_each_concurrent):

        let mut messages = consumer
            .messages()
            .await
            .unwrap()
            .for_each(|message| async move {
                println!("handle the message on subject {}", message.unwrap().subject);
            });

If you want each call to not block execution of code until it's finished - use a Task.
Neither our implementation of Stream, nor futures::StreamExt::each does not spawn any Tasks to be as lightweight as possible.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@geraldmwangi
Comment options

@Jarema
Comment options

@geraldmwangi
Comment options

Answer selected by geraldmwangi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants