Documentation
¶
Index ¶
- type JavascriptProcessor
- func (p *JavascriptProcessor) Configure(ctx context.Context, c config.Config) error
- func (p *JavascriptProcessor) Open(context.Context) error
- func (p *JavascriptProcessor) Process(_ context.Context, records []opencdc.Record) []sdk.ProcessedRecord
- func (p *JavascriptProcessor) Specification() (sdk.Specification, error)
- func (p *JavascriptProcessor) Teardown(context.Context) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JavascriptProcessor ¶ added in v0.13.4
type JavascriptProcessor struct {
sdk.UnimplementedProcessor
// contains filtered or unexported fields
}
Example ¶
p := NewJavascriptProcessor(log.Nop())
exampleutil.RunExample(p, exampleutil.Example{
Summary: "Modify a record's metadata and payload using JavaScript",
Description: "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`.",
Config: config.Config{
"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;
}`,
},
Have: opencdc.Record{
Metadata: map[string]string{
"existing-key": "existing-value",
},
Payload: opencdc.Change{
After: opencdc.RawData("world"),
},
},
Want: sdk.SingleRecord{
Metadata: map[string]string{
"existing-key": "existing-value",
"processed": "true",
},
Payload: opencdc.Change{
After: opencdc.RawData("hello, world"),
},
},
})
Output: processor transformed record: --- before +++ after @@ -1,12 +1,13 @@ { "position": null, "operation": "Operation(0)", "metadata": { - "existing-key": "existing-value" + "existing-key": "existing-value", + "processed": "true" }, "key": null, "payload": { "before": null, - "after": "world" + "after": "hello, world" } }
func NewJavascriptProcessor ¶
func NewJavascriptProcessor(logger log.CtxLogger) *JavascriptProcessor
func (*JavascriptProcessor) Open ¶ added in v0.13.4
func (p *JavascriptProcessor) Open(context.Context) error
func (*JavascriptProcessor) Process ¶ added in v0.13.4
func (p *JavascriptProcessor) Process(_ context.Context, records []opencdc.Record) []sdk.ProcessedRecord
func (*JavascriptProcessor) Specification ¶ added in v0.13.4
func (p *JavascriptProcessor) Specification() (sdk.Specification, error)
Click to show internal directories.
Click to hide internal directories.