github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/inputs/read_until.md (about)

     1  ---
     2  title: read_until
     3  type: input
     4  status: stable
     5  categories: ["Utility"]
     6  ---
     7  
     8  <!--
     9       THIS FILE IS AUTOGENERATED!
    10  
    11       To make changes please edit the contents of:
    12       lib/input/read_until.go
    13  -->
    14  
    15  import Tabs from '@theme/Tabs';
    16  import TabItem from '@theme/TabItem';
    17  
    18  
    19  Reads messages from a child input until a consumed message passes a [Bloblang query](/docs/guides/bloblang/about/), at which point the input closes.
    20  
    21  ```yaml
    22  # Config fields, showing default values
    23  input:
    24    label: ""
    25    read_until:
    26      input: {}
    27      check: ""
    28      restart_input: false
    29  ```
    30  
    31  Messages are read continuously while the query check returns false, when the query returns true the message that triggered the check is sent out and the input is closed. Use this to define inputs where the stream should end once a certain message appears.
    32  
    33  Sometimes inputs close themselves. For example, when the `file` input type reaches the end of a file it will shut down. By default this type will also shut down. If you wish for the input type to be restarted every time it shuts down until the query check is met then set `restart_input` to `true`.
    34  
    35  ### Metadata
    36  
    37  A metadata key `benthos_read_until` containing the value `final` is added to the first part of the message that triggers the input to stop.
    38  
    39  ## Fields
    40  
    41  ### `input`
    42  
    43  The child input to consume from.
    44  
    45  
    46  Type: `input`  
    47  Default: `{}`  
    48  
    49  ### `check`
    50  
    51  A [Bloblang query](/docs/guides/bloblang/about/) that should return a boolean value indicating whether the input should now be closed.
    52  
    53  
    54  Type: `string`  
    55  Default: `""`  
    56  
    57  ```yaml
    58  # Examples
    59  
    60  check: this.type == "foo"
    61  
    62  check: count("messages") >= 100
    63  ```
    64  
    65  ### `restart_input`
    66  
    67  Whether the input should be reopened if it closes itself before the condition has resolved to true.
    68  
    69  
    70  Type: `bool`  
    71  Default: `false`  
    72  
    73  ## Examples
    74  
    75  <Tabs defaultValue="Consume N Messages" values={[
    76  { label: 'Consume N Messages', value: 'Consume N Messages', },
    77  ]}>
    78  
    79  <TabItem value="Consume N Messages">
    80  
    81  A common reason to use this input is to consume only N messages from an input and then stop. This can easily be done with the [`count` function](/docs/guides/bloblang/functions/#count):
    82  
    83  ```yaml
    84  # Only read 100 messages, and then exit.
    85  input:
    86    read_until:
    87      check: count("messages") >= 100
    88      input:
    89        kafka:
    90          addresses: [ TODO ]
    91          topics: [ foo, bar ]
    92          consumer_group: foogroup
    93  ```
    94  
    95  </TabItem>
    96  </Tabs>
    97  
    98