custom_options/
custom_options.rs1use std::time::Duration;
2
3use tether_agent::{
4 PlugDefinition, PlugDefinitionCommon, PlugOptionsBuilder, TetherAgentOptionsBuilder,
5};
6
7fn main() {
8 let mut tether_agent = TetherAgentOptionsBuilder::new("example")
9 .id(None)
10 .host(Some("localhost"))
11 .port(Some(1883))
12 .username(Some("tether"))
13 .password(Some("sp_ceB0ss!"))
14 .build()
15 .expect("failed to create Tether Agent");
16
17 let output_plug = PlugOptionsBuilder::create_output("anOutput")
18 .role(Some("pretendingToBeSomethingElse"))
19 .qos(Some(2))
20 .retain(Some(true))
21 .build(&mut tether_agent)
22 .expect("failed to create output plug");
23 let input_wildcard_plug = PlugOptionsBuilder::create_input("everything")
24 .topic(Some("#"))
25 .build(&mut tether_agent);
26
27 let input_customid_plug = PlugOptionsBuilder::create_input("someData")
28 .role(None) .id(Some("specificIDonly"))
30 .build(&mut tether_agent);
31
32 println!("Agent looks like this: {:?}", tether_agent.description());
33 let (role, id, _) = tether_agent.description();
34 assert_eq!(role, "example");
35 assert_eq!(id, "any"); if let PlugDefinition::OutputPlug(p) = &output_plug {
38 println!("output plug: {:?}", p);
39 assert_eq!(p.topic_str(), "pretendingToBeSomethingElse/any/anOutput");
40 }
41
42 println!("wildcard input plug: {:?}", input_wildcard_plug);
43 println!("speific ID input plug: {:?}", input_customid_plug);
44
45 let payload =
46 rmp_serde::to_vec::<String>(&String::from("boo")).expect("failed to serialise payload");
47 tether_agent
48 .publish(&output_plug, Some(&payload))
49 .expect("failed to publish");
50
51 std::thread::sleep(Duration::from_millis(4000));
52}