Topic logs
Every message gets a sequence number in its topic's log. Subscribers replay history, resume after a disconnect or a server restart, and spot duplicates.
Open source · Rust · Apache-2.0
A publish/subscribe broker over WebSockets, written in Rust. One binary, a data directory, and a JSON protocol any language can speak.
docker pull ghcr.io/soumyadepp/popsub:0.2$ node example.mjsorders/42 #1: order 42 shipped^C$ node publish.mjs orders/cli "order 43 placed"published orders/cli #1$ node publish.mjs orders/cli "order 44 placed"published orders/cli #2$ node example.mjsorders/cli #1: order 43 placedorders/cli #2: order 44 placedorders/42 #2: order 42 shippedorders/42 #1.What you get
Every message gets a sequence number in its topic's log. Subscribers replay history, resume after a disconnect or a server restart, and spot duplicates.
Name a session when you connect, and your subscriptions and acknowledgement positions survive disconnects and server restarts.
QoS 1 is at-least-once per subscriber. A message that runs out of retries pauses that subscription, or goes to a dead-letter topic if you set one.
Subscribe to orders/# or sensors/+/temp, or share a topic across a group of workers so each message goes to one of them.
Per-topic grants, Argon2id passwords, JWTs and rate limits. Change accounts on a running server, and live connections follow at once.
Rust, TypeScript, Python and Go handle login, reconnection, resubscription, acknowledgements and deduplication, each held to one shared scenario suite.
Thirty seconds of code
Subscribe to every topic under orders/, publish one message and wait until it is stored,
then print what arrives. The session name means a restart carries on from where it stopped,
and starting from seq 1 also picks up topics created while it was away.
import { Client } from "popsub";
const client = await Client.connect({ url: "ws://127.0.0.1:8080", credentials: { username: "alice", password: "alice-password" }, sessionId: "orders-worker",});
const messages = await client.subscribe("orders/#", { seq: 1 });await client.publishConfirmed("orders/42", "order 42 shipped");
for await (const message of messages) { console.log(`${message.topic} #${message.seq}: ${message.payload}`);}import asyncio
from popsub import Client, ClientConfig, PasswordCredentials, StartFrom
async def main() -> None: config = ClientConfig( "ws://127.0.0.1:8080", PasswordCredentials("alice", "alice-password"), session_id="orders-worker", ) async with await Client.connect(config) as client: messages = await client.subscribe("orders/#", StartFrom.seq(1)) await client.publish_confirmed("orders/42", "order 42 shipped") async for message in messages: print(f"{message.topic} #{message.seq}: {message.payload}")
try: asyncio.run(main())except KeyboardInterrupt: passpackage main
import ( "context" "fmt" "log"
popsub "github.com/soumyadepp/popsub/clients/go")
func main() { ctx := context.Background() client, err := popsub.Connect(ctx, popsub.Config{ URL: "ws://127.0.0.1:8080", Credentials: popsub.PasswordCredentials("alice", "alice-password"), SessionID: "orders-worker", }) if err != nil { log.Fatal(err) } defer client.Close()
messages, err := client.Subscribe(ctx, "orders/#", popsub.FromSeq(1)) if err != nil { log.Fatal(err) } if _, err := client.PublishConfirmed(ctx, "orders/42", "order 42 shipped"); err != nil { log.Fatal(err) } for message := range messages.Messages() { fmt.Printf("%s #%d: %s\n", message.Topic, message.Seq, message.Payload) }}use popsub_sdk::{Client, ClientConfig, Credentials, StartFrom};
#[tokio::main]async fn main() -> Result<(), popsub_sdk::Error> { let config = ClientConfig::new( "ws://127.0.0.1:8080", Credentials::password("alice", "alice-password"), ) .session("orders-worker"); let client = Client::connect(config).await?;
let mut messages = client.subscribe("orders/#", StartFrom::Seq(1)).await?; client.publish_confirmed("orders/42", "order 42 shipped").await?;
while let Some(message) = messages.next().await { println!("{} #{}: {}", message.topic, message.seq, message.payload); } Ok(())}Install
docker pull ghcr.io/soumyadepp/popsub:0.2npm install popsubpip install popsubgo get github.com/soumyadepp/popsub/clients/go@latestcargo add popsub_sdkWhere it fits