Get started
In about five minutes you’ll run a server, create an account, subscribe from the language you use, and see a subscriber that was stopped pick up every message it missed.
-
Start a server. Pick one way and keep it running in its own terminal.
Download the archive for your machine and its checksum from Releases. This is macOS on Apple silicon; for Linux, use
x86_64-unknown-linux-gnuoraarch64-unknown-linux-gnu, andsha256sum -cinstead ofshasum -a 256 -c.Terminal window curl -LO https://github.com/soumyadepp/popsub/releases/download/v0.2.0/popsub-0.2.0-aarch64-apple-darwin.tar.gzcurl -LO https://github.com/soumyadepp/popsub/releases/download/v0.2.0/popsub-0.2.0-aarch64-apple-darwin.tar.gz.sha256shasum -a 256 -c popsub-0.2.0-aarch64-apple-darwin.tar.gz.sha256tar -xzf popsub-0.2.0-aarch64-apple-darwin.tar.gzcd popsub-0.2.0-aarch64-apple-darwin./popsub serverIt listens on
127.0.0.1:8080and creates the admin accountadminwith the passwordpassword. Those published defaults are only accepted onlocalhost.The container listens on all interfaces, so it refuses to start with the published defaults. Give it your own JWT secret and admin password:
Terminal window docker run --name popsub -p 8080:8080 -v popsub-data:/data \-e SERVER__JWT_SECRET="$(openssl rand -hex 32)" \-e SERVER_PASSWORD=choose-an-admin-password \ghcr.io/soumyadepp/popsub:0.2The admin account is
admin, with the password you chose. Data lives in thepopsub-datavolume.You need Rust 1.89 or newer.
Terminal window git clone https://github.com/soumyadepp/popsub.gitcd popsubmake serverIt listens on
127.0.0.1:8080and creates the admin accountadminwith the passwordpassword. Those published defaults are only accepted onlocalhost. -
Create an account. In a second terminal, in the same folder, create
alice, allowed to publish and subscribe to every topic underorders/. The admin’s password comes fromPOPSUB_PASSWORDand the new account’s fromPOPSUB_NEW_PASSWORD; leave either out andpopsubasks for it without echoing what you type.Terminal window POPSUB_PASSWORD=password POPSUB_NEW_PASSWORD=alice-password \./popsub users add alice --topic 'orders/#'Terminal window docker exec -e POPSUB_PASSWORD=choose-an-admin-password \-e POPSUB_NEW_PASSWORD=alice-password \popsub popsub users add alice --topic 'orders/#'Terminal window POPSUB_PASSWORD=password POPSUB_NEW_PASSWORD=alice-password \cargo run -p popsub -- users add alice --topic 'orders/#'It prints the new account:
Name: aliceRole: userEnabled: yesTopics: orders/#:both -
Run a subscriber. In a third terminal, set up a project in your language and save the example as shown. It logs in as
alicewith a session calledorders-worker, subscribes to every topic underorders/, publishes one message, and prints everything that arrives.Node 22 or newer.
Terminal window mkdir popsub-try && cd popsub-trynpm init -ynpm install popsubSave this as
example.mjsand runnode example.mjs:example.mjs 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}`);}Python 3.10 or newer.
Terminal window mkdir popsub-try && cd popsub-trypython3 -m venv .venv && . .venv/bin/activatepip install popsubSave this as
example.pyand runpython example.py:example.py import asynciofrom popsub import Client, ClientConfig, PasswordCredentials, StartFromasync 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:passGo 1.23 or newer.
Terminal window mkdir popsub-try && cd popsub-trygo mod init example.com/popsub-trygo get github.com/soumyadepp/popsub/clients/go@latestSave this as
main.goand rungo run .:main.go package mainimport ("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)}}Terminal window cargo new popsub-try && cd popsub-trycargo add popsub_sdkcargo add tokio --features macros,rt-multi-threadReplace
src/main.rswith this and runcargo run:src/main.rs 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(())}On a new server it prints its own message, then waits:
orders/42 #1: order 42 shipped#1is the message’s sequence number in the topicorders/42. Every topic numbers its messages 1, 2, 3 and so on. -
Publish from somewhere else. Back in the second terminal, the
popsub clientcommand logs in, subscribes to a topic, publishesHello from popsub clientto it and exits.Terminal window ./popsub client --username alice --password alice-password --topic orders/cliTerminal window docker exec popsub popsub client --username alice --password alice-password --topic orders/cliTerminal window cargo run -p popsub -- client --username alice --password alice-password --topic orders/cliYour subscriber prints it straight away, because
orders/climatchesorders/#:orders/cli #1: Hello from popsub client -
Watch it catch up. Stop the subscriber with Ctrl+C. Run the
popsub clientcommand from step 4 twice more, then start the subscriber again. It prints the two messages it missed, in order, then the new one it publishes itself:orders/cli #2: Hello from popsub clientorders/cli #3: Hello from popsub clientorders/42 #2: order 42 shippedThat’s the durable session at work. The server kept
orders-worker’s place in each topic it had joined, soorders/clicarried on from#2andorders/42didn’t repeat#1. The example subscribes fromseq1, which only matters for topics the session hasn’t joined yet: a topic created while it was stopped is read from its first message, so that isn’t missed either. A session survives disconnects and server restarts, as long as it comes back within a day and the messages are still kept, which by default is the last 1,000 per topic for up to an hour.
Where to go next
Section titled “Where to go next”examples/has a separate subscriber and publisher for each language.- The README covers configuration, TLS, running behind a proxy, health checks and managing users.
docs/DESIGN.mddescribes the protocol and every delivery guarantee precisely, anddocs/protocol/has a JSON Schema for every frame, for writing a client in another language.