ApexStream logoApexStream

ApexStream / docs

End-to-end demo — publish, subscribe, webhook to mock ERP

One publish powers three audiences at once: a live subscriber over WebSocket, a back-office system over a signed webhook, and operators via the dashboard audit + inspector. Runs locally with make demo in under 15 minutes.

What you'll see

  1. 1

    publisher → ApexStream

    A Node script publishes a small JSON order payload to channel `orders.events` every 2 seconds using the `@apexstream/client` SDK.

  2. 2

    subscriber receives in real time

    A second Node script (a stand-in for any web/Node app) subscribes to the same channel and prints every payload as it arrives over the same WebSocket gateway.

  3. 3

    webhook → mock ERP

    The same event is delivered out-of-band as a signed HTTP POST to a tiny Express server. The mock ERP recomputes HMAC-SHA256 over the raw body and prints `signature OK`.

Source — three small files

Full sources in examples/end-to-end-killer-demo/

publisher/publish.mjs

// publisher/publish.mjs (excerpt)
import { ApexStreamClient } from "@apexstream/client";

const client = new ApexStreamClient({
  url: process.env.APEXSTREAM_WS_URL,
  apiKey: process.env.APEXSTREAM_API_KEY,
  allowInsecureTransport: process.env.APEXSTREAM_WS_URL.startsWith("ws://"),
});

// Optional: register a webhook so the same publish is mirrored
// to your back-office over signed HTTP POST.
await fetch(`${process.env.APEXSTREAM_API_URL}/external/v1/webhooks`, {
  method: "POST",
  headers: {
    "content-type": "application/json",
    authorization: `Bearer ${process.env.APEXSTREAM_EXTERNAL_API_KEY}`,
  },
  body: JSON.stringify({
    project_id: process.env.APEXSTREAM_PROJECT_ID,
    target_url: process.env.WEBHOOK_URL,
    secret: process.env.WEBHOOK_SECRET,
    events: ["channel.message"],
    channel: "orders.events",
  }),
});

client.on("open", () => {
  setInterval(() => {
    client.publish("orders.events", {
      id: `ord_${Date.now()}`,
      sku: "sku-keyboard",
      qty: 1,
      amount_cents: 2999,
      ts: new Date().toISOString(),
    });
  }, 2000);
});

client.connect();

Run locally

Assumes the ApexStream stack is up (./apexstream.sh up --detach), extended realtime is enabled, and you have minted an app API key plus an External API key from the dashboard.

# 1. configure
cd examples/end-to-end-killer-demo
cp .env.example .env
$EDITOR .env  # fill APEXSTREAM_API_KEY, APEXSTREAM_PROJECT_ID, etc.

# 2. boot publisher + subscriber + mock-erp
make demo

# 3. follow the three logs side-by-side
make logs

# 4. trigger a one-shot publish
make publish

# 5. clean up
make down

See cloud quick start for account + key setup, and the full narrative walkthrough lives in the repo at docs/end-to-end-demo.md.