-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.go
71 lines (56 loc) · 1.4 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
// Dependencies of Turbine
"github.com/meroxa/turbine-go"
"github.com/meroxa/turbine-go/runner"
"log"
"github.com/ahamidi/kcschema"
)
func main() {
runner.Start(App{})
}
var _ turbine.App = (*App)(nil)
type App struct{}
func (a App) Run(v turbine.Turbine) error {
source, err := v.Resources("cck")
if err != nil {
return err
}
rr, err := source.Records("inbound", nil)
if err != nil {
return err
}
res := v.Process(rr, Format{})
dest, err := v.Resources("demopg")
if err != nil {
return err
}
err = dest.WriteWithConfig(res, "inbound_events", turbine.ResourceConfigs{
{Field: "key.converter", Value: "org.apache.kafka.connect.storage.StringConverter"},
{Field: "key.converter.schemas.enable", Value: "true"},
})
if err != nil {
return err
}
return nil
}
type Format struct{}
func (f Format) Process(stream []turbine.Record) []turbine.Record {
for i, record := range stream {
log.Printf("Original turbine Record: %+v", record)
sp, err := kcschema.Parse(kcschema.Payload(record.Payload))
if err != nil {
log.Printf("error casting Payload to Map: %s", err.Error())
break
}
log.Printf("Parsed payload: %+v", sp)
j, err := sp.AsKCSchemaJSON("inbound")
if err != nil {
log.Printf("error casting Payload to Map: %s", err.Error())
break
}
log.Printf("converted record with schema: %+v", string(j))
stream[i].Payload = j
}
return stream
}