A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://conduit.io/docs/using/processors/builtin/custom.javascript below:

custom.javascript | Conduit | Data Integration for Production Data Stores

custom.javascript

Run custom JavaScript code.

Description

A processor that makes it possible to process Conduit records using JavaScript.

The following helper functions and variables are available:

To find out what's possible with the JS processor, also refer to the documentation for goja, which is the JavaScript engine we use.

Configuration parameters
version: 2.2
pipelines:
- id: example
status: running
connectors:

processors:
- id: example
plugin: "custom.javascript"
settings:







script: ""


script.path: ""



sdk.schema.decode.key.enabled: "true"



sdk.schema.decode.payload.enabled: "true"



sdk.schema.encode.key.enabled: "true"



sdk.schema.encode.payload.enabled: "true"
Name Type Default Description script string

null

JavaScript code for this processor. It needs to have a function process() that accept a record and returns a record. The process() function can either modify the input record and return it, or create a new record. If a record needs to be filtered (dropped from the pipeline), then the process() function should return null.

script.path string

null

The path to a .js file containing the processor code.

sdk.schema.decode.key.enabled bool true

Whether to decode the record key using its corresponding schema from the schema registry.

sdk.schema.decode.payload.enabled bool true

Whether to decode the record payload using its corresponding schema from the schema registry.

sdk.schema.encode.key.enabled bool true

Whether to encode the record key using its corresponding schema from the schema registry.

sdk.schema.encode.payload.enabled bool true

Whether to encode the record payload using its corresponding schema from the schema registry.

Examples Modify a record's metadata and payload using JavaScript

In this example we use the custom.javascript processor to add a metadata key to the input record. It also prepends "hello, " to .Payload.After.

Configuration parameters
version: 2.2
pipelines:
- id: example
status: running
connectors:

processors:
- id: example
plugin: "custom.javascript"
settings:
script: |
function process(rec) {
rec.Metadata["processed"] = "true";
let existing = String.fromCharCode.apply(String, rec.Payload.After);
rec.Payload.After = RawData("hello, " + existing);
return rec;
}

Name Value script
function process(rec) {
rec.Metadata["processed"] = "true";
let existing = String.fromCharCode.apply(String, rec.Payload.After);
rec.Payload.After = RawData("hello, " + existing);
return rec;
}
Record difference
Before
After
1

{
1

{
2

  "position": null,
2

  "position": null,
3

  "operation": "Operation(0)",
3

  "operation": "Operation(0)",
4

  "metadata": {
4

  "metadata": {
5
-
    "existing-key": "existing-value"
5
+
    "existing-key": "existing-value",



6
+
    "processed": "true"
6

  },
7

  },
7

  "key": null,
8

  "key": null,
8

  "payload": {
9

  "payload": {
9

    "before": null,
10

    "before": null,
10
-
    "after": "world"
11
+
    "after": "hello, world"
11

  }
12

  }
12

}
13

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4