-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unsub/disconnect on drop, separate out examples
- Loading branch information
Devdutt Shenoi
committed
Feb 16, 2022
1 parent
150cec5
commit b25ba08
Showing
5 changed files
with
126 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use tokio::{task, time}; | ||
|
||
use rumqttc::{self, MqttOptions, QoS, ReqHandler}; | ||
use std::error::Error; | ||
use std::time::Duration; | ||
|
||
#[tokio::main(worker_threads = 1)] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
pretty_env_logger::init(); | ||
// color_backtrace::install(); | ||
|
||
let mut mqttoptions = MqttOptions::new("test-pub", "localhost", 1883); | ||
mqttoptions.set_keep_alive(Duration::from_secs(5)); | ||
|
||
let (client, mut sub_handler) = ReqHandler::new(mqttoptions, 10); | ||
task::spawn(async move { | ||
sub_handler.start().await.unwrap(); | ||
}); | ||
|
||
let mut publisher = client.publisher("hello/world"); | ||
|
||
publisher.qos = QoS::ExactlyOnce; | ||
publisher.retain = false; | ||
for i in 1..=10 { | ||
publisher.publish(vec![1; i]).await.unwrap(); | ||
|
||
time::sleep(Duration::from_secs(1)).await; | ||
} | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use tokio::task; | ||
|
||
use rumqttc::{self, MqttOptions, QoS, ReqHandler}; | ||
use std::error::Error; | ||
use std::time::Duration; | ||
|
||
#[tokio::main(worker_threads = 1)] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
pretty_env_logger::init(); | ||
// color_backtrace::install(); | ||
|
||
let mut mqttoptions = MqttOptions::new("test-sub", "localhost", 1883); | ||
mqttoptions.set_keep_alive(Duration::from_secs(5)); | ||
|
||
let (client, mut sub_handler) = ReqHandler::new(mqttoptions, 10); | ||
task::spawn(async move { | ||
sub_handler.start().await.unwrap(); | ||
}); | ||
|
||
let mut subscriber = client.subscriber("hello/world", QoS::AtMostOnce).await?; | ||
|
||
loop { | ||
let publish = subscriber.next().await?; | ||
println!("{:?}", publish); | ||
if publish.topic.contains("10") { | ||
subscriber.unsubscribe().await?; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters