taps

Crates.iotaps
lib.rstaps
version0.2.2
sourcesrc
created_at2023-10-15 03:53:20.286403
updated_at2023-10-15 05:06:55.806998
descriptiontaps (Tokio Asynchronous Pub/Sub) is an in-process async message broker that can be used for messaging between spawned tokio tasks.
homepagehttps://github.com/matthewjberger/taps
repositoryhttps://github.com/matthewjberger/taps
max_upload_size
id1003467
size41,253
Matthew J. Berger (matthewjberger)

documentation

README

Taps - (Tokio Async Pub/Sub)

github crates.io docs.rs

taps is an in-process async message broker built on the tokio runtime that allows multiple clients to communicate with each other through a central broker, routing messages based on topics.

Features

  • Topic-based Routing: Easily send and receive messages based on topics.
  • Asynchronous: Built for asynchronous environments, utilizing the power of Tokio.
  • Scalable: Designed to handle multiple clients communicating simultaneously.

Quick Start

Installation

Add the following to your Cargo.toml:

[dependencies]
taps = "0.2.2"
tokio = { version = "1.33.0", features = ["full"] }

Usage

use taps::{Broker, Client};

#[tokio::main]
async fn main() {
    let mut broker = Broker::new();
    let (worker_tx, worker_rx) = tokio::sync::mpsc::channel(32);
    tokio::spawn(async move {
        broker.run(worker_rx).await;
    });

    let mut client1 = Client::new(worker_tx.clone());
    client1.subscribe("topic1".to_string()).await;

    let mut client2 = Client::new(worker_tx.clone());
    client2.subscribe("topic1".to_string()).await;

    client1
        .publish("topic1".to_string(), "Hello from client1!".to_string())
        .await;
    if let Some(msg_from_client2) = client2.receive("topic1").await {
        println!("{msg_from_client2}"); // Outputs: "Hello from client1!"
    }
}
Commit count: 11

cargo fmt