Skip to content

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.

  1. 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-gnu or aarch64-unknown-linux-gnu, and sha256sum -c instead of shasum -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.gz
    curl -LO https://github.com/soumyadepp/popsub/releases/download/v0.2.0/popsub-0.2.0-aarch64-apple-darwin.tar.gz.sha256
    shasum -a 256 -c popsub-0.2.0-aarch64-apple-darwin.tar.gz.sha256
    tar -xzf popsub-0.2.0-aarch64-apple-darwin.tar.gz
    cd popsub-0.2.0-aarch64-apple-darwin
    ./popsub server

    It listens on 127.0.0.1:8080 and creates the admin account admin with the password password. Those published defaults are only accepted on localhost.

  2. Create an account. In a second terminal, in the same folder, create alice, allowed to publish and subscribe to every topic under orders/. The admin’s password comes from POPSUB_PASSWORD and the new account’s from POPSUB_NEW_PASSWORD; leave either out and popsub asks for it without echoing what you type.

    Terminal window
    POPSUB_PASSWORD=password POPSUB_NEW_PASSWORD=alice-password \
    ./popsub users add alice --topic 'orders/#'

    It prints the new account:

    Name: alice
    Role: user
    Enabled: yes
    Topics: orders/#:both
  3. Run a subscriber. In a third terminal, set up a project in your language and save the example as shown. It logs in as alice with a session called orders-worker, subscribes to every topic under orders/, publishes one message, and prints everything that arrives.

    Node 22 or newer.

    Terminal window
    mkdir popsub-try && cd popsub-try
    npm init -y
    npm install popsub

    Save this as example.mjs and run node 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}`);
    }

    On a new server it prints its own message, then waits:

    orders/42 #1: order 42 shipped

    #1 is the message’s sequence number in the topic orders/42. Every topic numbers its messages 1, 2, 3 and so on.

  4. Publish from somewhere else. Back in the second terminal, the popsub client command logs in, subscribes to a topic, publishes Hello from popsub client to it and exits.

    Terminal window
    ./popsub client --username alice --password alice-password --topic orders/cli

    Your subscriber prints it straight away, because orders/cli matches orders/#:

    orders/cli #1: Hello from popsub client
  5. Watch it catch up. Stop the subscriber with Ctrl+C. Run the popsub client command 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 client
    orders/cli #3: Hello from popsub client
    orders/42 #2: order 42 shipped

    That’s the durable session at work. The server kept orders-worker’s place in each topic it had joined, so orders/cli carried on from #2 and orders/42 didn’t repeat #1. The example subscribes from seq 1, 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.

  • 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.md describes the protocol and every delivery guarantee precisely, and docs/protocol/ has a JSON Schema for every frame, for writing a client in another language.