Topics
Topics provide a general-purpose messaging layer on top of Ironflow’s NATS infrastructure. Use them for service-to-service communication, analytics, or notifications — without triggering workflows.
Topics vs Events
| Feature | emit() | publish() |
|---|---|---|
| Namespace | events: | topic: |
| Triggers Functions? | Yes | No |
| Use Case | Business logic triggers. | Real-time messages / broadcasting. |
Publishing to Topics
From Application Code
import { createClient } from "@ironflow/node";
const ironflow = createClient({ apiKey: process.env.IRONFLOW_API_KEY });
await ironflow.publish("notifications.email", { to: "user@example.com", body: "Welcome to Ironflow!",});client := ironflow.NewClient(ironflow.ClientConfig{ APIKey: os.Getenv("IRONFLOW_API_KEY"),})
client.Publish(ctx, "notifications.email", map[string]string{ "to": "user@example.com",})From Within a Workflow
Use step.publish() to emit a message as a durable step. This ensures that if the workflow retries, the message is not published more than once.
export const myFn = ironflow.createFunction(config, async ({ step }) => { // Durable publish — memoized and observable await step.publish("analytics.workflow_step", { status: "reached" });});Subscribing to Topics
Topics use the topic: prefix for subscriptions.
import { ironflow } from "@ironflow/browser";
await ironflow.subscribe("topic:notifications.>", { onEvent: (event) => console.log("Broadcasting:", event.data),});# Listen to all developer topicsironflow subscribe "topic:>"Clean Patterns
Use topic:notifications.* to listen to specific categories, or topic:> to listen to all custom messages in the system.