github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/conditions/about.md (about) 1 --- 2 title: Conditions 3 sidebar_label: About 4 --- 5 6 Conditions are boolean queries that can be executed based on the contents of a message, some [processors][processors] such as [`switch`][processor.switch] use conditions for expressing their logic. There are many options but the most powerful type is the [`bloblang` condition][condition.bloblang]. 7 8 Conditions themselves can modify ([`not`][condition.not]) and combine ([`and`][condition.and], [`or`][condition.or]) other conditions, and can therefore be used to create complex boolean expressions. 9 10 The format of a condition is similar to other Benthos types: 11 12 ```yml 13 condition: 14 bloblang: meta("kafka_topic") == "foo" 15 ``` 16 17 And is usually found as the child of a processor: 18 19 ```yml 20 pipeline: 21 processors: 22 - switch: 23 - condition: 24 bloblang: meta("kafka_topic") == "foo" 25 processors: 26 - resource: foo 27 - processors: 28 - resource: bar 29 ``` 30 31 ### Batching and Multipart Messages 32 33 All conditions can be applied to a multipart message, which is synonymous with a batch. Some conditions target a specific part of a message batch, and require you specify the target index with the field `part`. 34 35 Part indexes can be negative, and if so the part will be selected from the end counting backwards starting from -1. E.g. if part = -1 then the selected part will be the last part of the message, if part = -2 then the part before the last element with be selected, and so on. 36 37 ### Reusing Conditions 38 39 Sometimes large chunks of logic are reused across processors, or nested multiple times as branches of a larger condition. It is possible to avoid writing duplicate condition configs by using the [resource condition][condition.resource]. 40 41 import ComponentSelect from '@theme/ComponentSelect'; 42 43 <ComponentSelect type="conditions"></ComponentSelect> 44 45 [processors]: /docs/components/processors/about 46 [processor.switch]: /docs/components/processors/switch 47 [condition.bloblang]: /docs/components/conditions/bloblang 48 [condition.and]: /docs/components/conditions/and 49 [condition.or]: /docs/components/conditions/or 50 [condition.not]: /docs/components/conditions/not 51 [condition.resource]: /docs/components/conditions/resource