- Docs
- Introduction
- Using QPub
Using QPub
Mental model
Account
└── Project
├── API keys
├── Channels (pub/sub topics)
└── Queues (durable jobs)
| Concept | Role |
|---|---|
| Account | Org/billing context in the dashboard |
| Project | Isolation boundary for traffic and keys |
| API key | publicId:secret credential for REST and Socket |
| Channel | Named topic string for pub/sub |
| Queue | Named durable job stream (REST) |
| Alias | Optional client identity attached to a connection or message |
Two client types
Socket (QPub.Socket)
Persistent WebSocket connection. Use for:
- Subscribing to channels
- Publishing from clients that already hold a connection
- Connection lifecycle (reconnect, ping)
REST (QPub.Rest)
HTTP-only. Use for:
- Publishing from servers and cron jobs
- Batch publish to multiple channels
- Issuing JWTs / creating token requests
- Queue enqueue and workers
REST does not subscribe to channels.
Typical workflows
Real-time app
- Create a project and API key in the dashboard.
- On your server, keep the API key secret.
- For browsers, issue a JWT or signed token request with limited permissions.
- Client creates
QPub.Socket, waits forconnected, thenchannels.get(name).subscribe(...). - Servers publish with
QPub.Restor another Socket client.
Server publish only
import { QPub } from "@qpub/sdk";
const rest = new QPub.Rest({ apiKey: process.env.QPUB_API_KEY });
await rest.channels.get("notifications").publish({ text: "Hello" });
Background jobs
const rest = new QPub.Rest({ apiKey: process.env.QPUB_API_KEY });
await rest.queues.enqueue("emails", { to: "[email protected]" });
// Blocks until stopWorker() is called
await rest.queues.runWorker("emails", async (job) => {
// process job.payload
return { ok: true };
});
// rest.queues.stopWorker();
Next steps
Previous
About QPub
Next
Quickstart Guide