-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
44 lines (37 loc) · 1.03 KB
/
main.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
package main
import (
"fmt"
dcpkafka "github.com/Trendyol/go-dcp-kafka"
"github.com/Trendyol/go-dcp-kafka/couchbase"
"github.com/Trendyol/go-dcp-kafka/kafka"
"github.com/Trendyol/go-dcp-kafka/kafka/message"
)
func mapper(event couchbase.Event) []message.KafkaMessage {
// return nil if you wish to discard the event
return []message.KafkaMessage{
{
Headers: nil,
Key: event.Key,
Value: event.Value,
},
}
}
type sinkResponseHandler struct {
}
func (s *sinkResponseHandler) OnSuccess(ctx *kafka.SinkResponseHandlerContext) {
fmt.Printf("OnSuccess Key: %v, Len: %v\n", string(ctx.Message.Key), len(ctx.Message.Value))
}
func (s *sinkResponseHandler) OnError(ctx *kafka.SinkResponseHandlerContext) {
fmt.Printf("OnError Key: %v, Len: %v, Err: %v\n", string(ctx.Message.Key), len(ctx.Message.Value), ctx.Err)
}
func main() {
c, err := dcpkafka.NewConnectorBuilder("config.yml").
SetMapper(mapper).
SetSinkResponseHandler(&sinkResponseHandler{}).
Build()
if err != nil {
panic(err)
}
defer c.Close()
c.Start()
}