|
| 1 | +# trigger-event |
| 2 | + |
| 3 | +This agent writes a new record (an "event") to a different topic, based on a condition. |
| 4 | +It can also optionally drop the record from the main flow of the pipeline. |
| 5 | + |
| 6 | +This agent is different from the [dispatch agent](dispatch.md) as the record that is sent to the new topic is a new record, not the same record that was received. |
| 7 | + |
| 8 | +### Example |
| 9 | + |
| 10 | +This is an example using the `trigger-event` agent to write a new record to a different topic when a condition is met. |
| 11 | + |
| 12 | +```yaml |
| 13 | + - name: "Split some text" |
| 14 | + type: "text-splitter" |
| 15 | + input: input-topic-splitter |
| 16 | + configuration: |
| 17 | + .... |
| 18 | + |
| 19 | + - name: "Trigger event on last chunk" |
| 20 | + type: "trigger-event" |
| 21 | + output: output-topic-chunks |
| 22 | + configuration: |
| 23 | + destination: drop-stale-chunks-topic |
| 24 | + continue-processing: true |
| 25 | + when: fn:toInt(properties.text_num_chunks) == (fn:toInt(properties.chunk_id) + 1) |
| 26 | + fields: |
| 27 | + - name: "value.filename" |
| 28 | + expression: "key.filename" |
| 29 | +``` |
| 30 | +
|
| 31 | +In this example the `text-splitter` agent splits a text into a set of chunks. |
| 32 | +When the last chunk is processed, the `trigger-event` agent writes a new record to the `drop-stale-chunks-topic` topic. |
| 33 | +The new record will have a filename field in the value part ("value.filename"). |
| 34 | + |
| 35 | +## Defining the contents of the output record |
| 36 | + |
| 37 | +The `trigger-event` agent configures a set of fields that will be written to the output record. |
| 38 | +As usual you can write to the key part, the value part, and the properties of the record. |
| 39 | +Use the [expression language](../../building-applications/expression-language.md) to define the fields and write the expression. |
| 40 | + |
| 41 | + |
| 42 | +### Aborting the processing downstream |
| 43 | + |
| 44 | +The `trigger-event` agent can also abort the processing of the record downstream by setting the `continue-processing` property to `false`. |
| 45 | +This is useful in cases where you have some system events that you want to write to a different topic, but you don't want to continue processing the record downstream. |
| 46 | + |
| 47 | +### Configuration |
| 48 | + |
| 49 | +Check out the full configuration properties in the [API Reference page](../../building-applications/api-reference/agents.md#trigger-event). |
0 commit comments