Skip to main content

Crate topiq

Crate topiq 

Source
Expand description

Lightweight TCP-based pub/sub message broker.

This crate re-exports the consumer-facing API so users only need a single dependency.

§Quick start

use std::time::Duration;
use topiq::{Client, ConnectOptions};

#[tokio::main]
async fn main() -> topiq::Result<()> {
    let client = Client::connect(ConnectOptions::default()).await?;

    // Publish (accepts &str, String, Vec<u8>, Bytes, etc.)
    client.publish("greet", "hello world").await?;

    // Subscribe
    let mut sub = client.subscribe("greet").await?;
    let msg = sub.next_message().await.unwrap();
    assert_eq!(msg.payload.as_ref(), b"hello world");

    // Request/reply
    let reply = client.request("service.echo", "ping", Duration::from_secs(5)).await?;

    client.close().await;
    Ok(())
}

Add topiq to your Cargo.toml:

[dependencies]
topiq = "0.1"

Structs§

Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
Client
Async client for the topiq message broker.
ConnectOptions
Options for connecting to a topiq broker.
Message
A message flowing through the pub/sub system.
Subject
A validated subject string used for topic-based pub/sub routing.
SubscriptionStream
An async stream of messages for a subscription.

Enums§

TopiqError
Errors that can occur in the topiq system.

Type Aliases§

Result