Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of infinite subscriber #16

Open
Farkal opened this issue Feb 25, 2020 · 0 comments
Open

Example of infinite subscriber #16

Farkal opened this issue Feb 25, 2020 · 0 comments

Comments

@Farkal
Copy link

Farkal commented Feb 25, 2020

Hey, i have some issue while making an infinite subscriber.
Here is the code:

let addr = std::env::var("NATS_ADDR").unwrap_or_else(|_| "127.0.0.1:4222".into());
let nats_client = Client::new(vec![addr.parse().unwrap()]);
nats_client.connect().await;

let subject = "test".parse().unwrap()
let (_, mut subscription) = nats_client.subscribe(&subject, 1024).await.unwrap();

loop {
        let message = subscription.next().await.unwrap();
        let message = String::from_utf8(message.into_payload()).unwrap();
        info!("Nats message received {}", message);
}

It works but I can't exit the program :/ (no SIGINT catch ?)
I think having an example of this use case should be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant