Global Helpers
publish()
Signature
Section titled “Signature”publish() — returns struct
Available in: controller, model, mapper, migrator, migration, tabledefinition
Category: Channel Functions
Description
Section titled “Description”Publish an event to a channel. Delegates to the in-memory Channel engine or the DatabaseAdapter depending on the adapter argument (or the global channelAdapter setting). Can be called from controllers, models, jobs, or anywhere with access to global helpers.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
channel | string | yes | — | The channel name to publish to (e.g. “user.42”). |
event | string | yes | — | The event type (e.g. “notification”, “update”). |
data | string | yes | — | The event data as a string (typically JSON). |
adapter | string | no | — | Adapter to use: “memory” (default) or “database”. |
Examples
Section titled “Examples”// 1. Publish a notification event to a user-specific channel (in-memory adapter)
data = serializeJSON({message = "Your order has shipped!", orderId = 42});
result = publish(channel="user.42", event="notification", data=data);
// result -> {success: true, ...}
// 2. Publish an update event using the database adapter for persistence
data = serializeJSON({status = "active", updatedAt = Now()});
result = publish(channel="products", event="update", data=data, adapter="database");
// 3. Broadcast a chat message to a room channel
result = publish(
channel = "chat.room.5",
event = "message",
data = serializeJSON({user = "alice", text = "Hello everyone!"})
);