#communication #tether #connect #tether-agent

tether-agent

Standardised use of MQTT and MessagePack for inter-process communication

33 releases

new 4.3.1-alpha Apr 24, 2025
0.14.2 Dec 24, 2024
0.13.0 Jul 22, 2024
0.12.1 Nov 10, 2023
0.8.4 Jul 10, 2023

#281 in Concurrency

Download history 16/week @ 2025-01-06 9/week @ 2025-01-13 6/week @ 2025-01-20 49/week @ 2025-01-27 29/week @ 2025-02-03 79/week @ 2025-02-10 37/week @ 2025-02-17 28/week @ 2025-02-24 12/week @ 2025-03-03 9/week @ 2025-03-10 7/week @ 2025-03-17 8/week @ 2025-03-24 2/week @ 2025-03-31 315/week @ 2025-04-07 402/week @ 2025-04-14 261/week @ 2025-04-21

980 downloads per month
Used in 10 crates

MIT license

75KB
1.5K SLoC

Tether Agent for Rust

Create and Connect

Build a Tether Agent using defaults, and connect it automatically:

 let mut agent = TetherAgentOptionsBuilder::new("RustDemoAgent")
        .build()
        .expect("failed to connect Tether");

Send Messages

Create a Channel Sender, passing in a ref to the Tether Agent you created:

    let sender_definition = PlugOptionsBuilder::create_sender("customValues")
        .build(&mut agent)
        .expect("failed to create sender");

If your data structure can be Serialised using serde, go ahead and encode+publish in one step:

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct CustomStruct {
    foo: String,
    bar: f32,
}
/// ...
        let custom_message = CustomStruct {
            foo: "hello".into(),
            bar: 0.42,
        };
        agent
            .encode_and_publish(&sender_definition, custom_message)
            .unwrap();

Or encode first and use agent.send

Receive Messages

Create a Channel Receiver:

    let receiver_defintion = PlugOptionsBuilder::create_input("customValues")
        .build(&mut agent)
        .expect("failed to create receiver");

And check for messages synchronously:

if let Some((topic, payload)) = agent.check_messages() {
  // Always check against the Channel this message "belongs" to!
  if receiver_defintion.matches(&topic) {
      // Decode the message payload, if applicable
      let decoded = rmp_serde::from_slice::<CustomStruct>::(&payload);
      ...
  }

Dependencies

~9–22MB
~326K SLoC