# trigger.topic

Runs every time kv.message.publish sends a message on --topic (the publisher's channel)

# trigger.topic

```
trigger.topic --topic TEXT → topic
```

Runs every time [`kv.message.publish`](/nodes/kv/kv.message.publish.md) sends a message on `--topic` (the publisher's channel). It is the project's in-process pub/sub, for work that should happen after a request answered (send the mail, resize the image, recompute a total) without making the request wait. Answers one key, `topic`: `{ topic, message, node_id }` — `topic` the `--topic` it listens on, `message` what was published (`input.topic.message`, `$trigger.message`). Messages are not stored: a subscriber that is not active when the publish happens never sees it.

## Flags

- `--topic` (required): The topic to listen on — the channel [`kv.message.publish`](/nodes/kv/kv.message.publish.md) sends on.

## Examples

### Do the slow part after the request

```
| trigger.topic --topic order.placed
```

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

It answers:

```json
{
  "topic": {
    "topic": "order.placed",
    "message": {
      "order_id": "o_91",
      "email": "a@example.com"
    },
    "node_id": "n0"
  }
}
```
