github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/inputs/generate.md (about) 1 --- 2 title: generate 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/generate.go 13 --> 14 15 import Tabs from '@theme/Tabs'; 16 import TabItem from '@theme/TabItem'; 17 18 19 Generates messages at a given interval using a [Bloblang](/docs/guides/bloblang/about) 20 mapping executed without a context. This allows you to generate messages for 21 testing your pipeline configs. 22 23 Introduced in version 3.40.0. 24 25 ```yaml 26 # Config fields, showing default values 27 input: 28 label: "" 29 generate: 30 mapping: "" 31 interval: 1s 32 count: 0 33 ``` 34 35 ## Fields 36 37 ### `mapping` 38 39 A [bloblang](/docs/guides/bloblang/about) mapping to use for generating messages. 40 41 42 Type: `string` 43 Default: `""` 44 45 ```yaml 46 # Examples 47 48 mapping: root = "hello world" 49 50 mapping: root = {"test":"message","id":uuid_v4()} 51 ``` 52 53 ### `interval` 54 55 The time interval at which messages should be generated, expressed either as a duration string or as a cron expression. If set to an empty string messages will be generated as fast as downstream services can process them. Cron expressions can specify a timezone by prefixing the expression with `TZ=<location name>`, where the location name corresponds to a file within the IANA Time Zone database. 56 57 58 Type: `string` 59 Default: `"1s"` 60 61 ```yaml 62 # Examples 63 64 interval: 5s 65 66 interval: 1m 67 68 interval: 1h 69 70 interval: '@every 1s' 71 72 interval: 0,30 */2 * * * * 73 74 interval: TZ=Europe/London 30 3-6,20-23 * * * 75 ``` 76 77 ### `count` 78 79 An optional number of messages to generate, if set above 0 the specified number of messages is generated and then the input will shut down. 80 81 82 Type: `int` 83 Default: `0` 84 85 ## Examples 86 87 <Tabs defaultValue="Cron Scheduled Processing" values={[ 88 { label: 'Cron Scheduled Processing', value: 'Cron Scheduled Processing', }, 89 { label: 'Generate 100 Rows', value: 'Generate 100 Rows', }, 90 ]}> 91 92 <TabItem value="Cron Scheduled Processing"> 93 94 A common use case for the generate input is to trigger processors on a schedule so that the processors themselves can behave similarly to an input. The following configuration reads rows from a PostgreSQL table every 5 minutes. 95 96 ```yaml 97 input: 98 generate: 99 interval: '@every 5m' 100 mapping: 'root = {}' 101 processors: 102 - sql_select: 103 driver: postgres 104 dsn: postgres://foouser:foopass@localhost:5432/testdb?sslmode=disable 105 table: foo 106 columns: [ "*" ] 107 ``` 108 109 </TabItem> 110 <TabItem value="Generate 100 Rows"> 111 112 The generate input can be used as a convenient way to generate test data. The following example generates 100 rows of structured data by setting an explicit count. The interval field is set to empty, which means data is generated as fast as the downstream components can consume it. 113 114 ```yaml 115 input: 116 generate: 117 count: 100 118 interval: "" 119 mapping: | 120 root = if random_int() % 2 == 0 { 121 { 122 "type": "foo", 123 "foo": "is yummy" 124 } 125 } else { 126 { 127 "type": "bar", 128 "bar": "is gross" 129 } 130 } 131 ``` 132 133 </TabItem> 134 </Tabs> 135 136