# kv.message.publish

Publishes --body to the pipelines listening on --topic

# kv.message.publish

```
kv.message.publish --topic TEXT --body JSON → message
```

Publishes `--body` to the pipelines listening on `--topic`. It reaches every active pipeline that starts with `trigger.topic --topic <same>` — the project's in-process pub/sub, for work that should happen after the request is answered. Adds `message: { topic, delivered }` (how many listeners received it) and keeps the rest of the payload. Messages are not stored; an empty `--body` is refused.

## Flags

- `--topic` (required): The topic to send on — the one `trigger.topic --topic` listens to.
- `--body` (required): What to send — a literal or {{ expr }}; a whole {{ }} keeps its type.

## Examples

### Hand off slow work after answering

```
| kv.message.publish --topic order.placed --body "{{ { order_id: input.query.rows[0]._key, email: $trigger.body.email } }}"
```

A pipeline starting with `trigger.topic --topic order.placed` receives the body as `input.topic.message`.

It answers:

```json
{
  "message": {
    "topic": "order.placed",
    "delivered": 1
  }
}
```
