Deployment channel
Use channels for live event streams where clients subscribe to status changes. This example publishes deployment progress and lets a dashboard read recent events after it reconnects.
Configure the app
Section titled “Configure the app”import { backend } from "@layeron/core"import { realtime } from "@layeron/modules"
const app = backend()const live = realtime({ name: "ops", historyLimit: 200,})app.use(live)Publish deployment progress
Section titled “Publish deployment progress”app.post("/deployments/:deploymentId/events", async (request) => { const pathSegments = new URL(request.url).pathname.split("/") const deploymentId = pathSegments[2] const body = await request.json() const channel = live.channel(`deployment_${deploymentId}`)
return await channel.broadcast({ type: body.type, data: { deploymentId: deploymentId, status: body.status, step: body.step, message: body.message, }, idempotencyKey: body.eventId, })})Read recent events
Section titled “Read recent events”app.get("/deployments/:deploymentId/events", async (request) => { const pathSegments = new URL(request.url).pathname.split("/") const deploymentId = pathSegments[2] return await live.channel(`deployment_${deploymentId}`).history({ limit: Number(new URL(request.url).searchParams.get("limit") ?? 50), cursor: new URL(request.url).searchParams.get("cursor") ?? undefined, })})Publish tenant-wide alerts
Section titled “Publish tenant-wide alerts”app.post("/tenants/:tenantId/alerts", async (request) => { const pathSegments = new URL(request.url).pathname.split("/") const tenantId = pathSegments[2] const body = await request.json()
return await live.channel(`tenant_${tenantId}:alerts`).publish({ type: "alert.created", data: { title: body.title, severity: body.severity, runbookUrl: body.runbookUrl, }, })})Use one channel per stream you want clients to subscribe to or replay.