github.com/Jeffail/benthos/v3@v3.65.0/lib/message/batch/docs.go (about)

     1  package batch
     2  
     3  import "github.com/Jeffail/benthos/v3/internal/docs"
     4  
     5  // FieldSpec returns a spec for a common batching field.
     6  func FieldSpec() docs.FieldSpec {
     7  	return docs.FieldSpec{
     8  		Name: "batching",
     9  		Type: docs.FieldTypeObject,
    10  		Description: `
    11  Allows you to configure a [batching policy](/docs/configuration/batching).`,
    12  		Examples: []interface{}{
    13  			map[string]interface{}{
    14  				"count":     0,
    15  				"byte_size": 5000,
    16  				"period":    "1s",
    17  			},
    18  			map[string]interface{}{
    19  				"count":  10,
    20  				"period": "1s",
    21  			},
    22  			map[string]interface{}{
    23  				"count":  0,
    24  				"period": "1m",
    25  				"check":  `this.contains("END BATCH")`,
    26  			},
    27  		},
    28  		Children: docs.FieldSpecs{
    29  			docs.FieldInt(
    30  				"count",
    31  				"A number of messages at which the batch should be flushed. If `0` disables count based batching.",
    32  			),
    33  			docs.FieldInt(
    34  				"byte_size",
    35  				"An amount of bytes at which the batch should be flushed. If `0` disables size based batching.",
    36  			).HasDefault(0),
    37  			docs.FieldString(
    38  				"period",
    39  				"A period in which an incomplete batch should be flushed regardless of its size.",
    40  				"1s", "1m", "500ms",
    41  			).HasDefault(""),
    42  			docs.FieldBloblang(
    43  				"check",
    44  				"A [Bloblang query](/docs/guides/bloblang/about/) that should return a boolean value indicating whether a message should end a batch.",
    45  				`this.type == "end_of_transaction"`,
    46  			).HasDefault(""),
    47  			docs.FieldDeprecated("condition").HasType(docs.FieldTypeCondition).OmitWhen(func(v, _ interface{}) (string, bool) {
    48  				m, ok := v.(map[string]interface{})
    49  				if !ok {
    50  					return "", false
    51  				}
    52  				return "field condition is deprecated in favour of check", m["type"] == "static" && m["static"] == false
    53  			}),
    54  			docs.FieldAdvanced(
    55  				"processors",
    56  				"A list of [processors](/docs/components/processors/about) to apply to a batch as it is flushed. This allows you to aggregate and archive the batch however you see fit. Please note that all resulting messages are flushed as a single batch, therefore splitting the batch into smaller batches using these processors is a no-op.",
    57  				[]map[string]interface{}{
    58  					{
    59  						"archive": map[string]interface{}{
    60  							"format": "lines",
    61  						},
    62  					},
    63  				},
    64  				[]map[string]interface{}{
    65  					{
    66  						"archive": map[string]interface{}{
    67  							"format": "json_array",
    68  						},
    69  					},
    70  				},
    71  				[]map[string]interface{}{
    72  					{
    73  						"merge_json": struct{}{},
    74  					},
    75  				},
    76  			).Array().HasType(docs.FieldTypeProcessor).Optional(),
    77  		},
    78  	}
    79  }