Skip to content

Commit

Permalink
chore: add default mapper example (#61)
Browse files Browse the repository at this point in the history
* chore: add default mapper example

* chore: fix integration test

* chore: remove nil
  • Loading branch information
oguzyildirim authored Nov 12, 2023
1 parent a573d05 commit 33db364
Show file tree
Hide file tree
Showing 12 changed files with 904 additions and 15 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func main() {

[File Config](example/simple/main.go)

[File Config](example/default-mapper/main.go)

## Configuration

### Dcp Configuration
Expand Down Expand Up @@ -137,6 +139,12 @@ Check out on [go-dcp](https://github.com/Trendyol/go-dcp#configuration)
You can also use all DCP-related metrics explained [here](https://github.com/Trendyol/go-dcp#exposed-metrics).
All DCP-related metrics are automatically injected. It means you don't need to do anything.

## Breaking Changes

| Date taking effect | Date announced | Change | How to check |
|--------------------| ---- |---- |-----------------|
| November 11, 2023 | November 11, 2023 | Creating connector via builder | Compile project |

## Contributing

Go Dcp Kafka is always open for direct contributions. For more information please check
Expand Down
37 changes: 29 additions & 8 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *connector) getTopicName(collectionName string, messageTopic string) str
return topic
}

func NewConnector(cfg any, mapper Mapper) (Connector, error) {
func newConnector(cfg any, mapper Mapper) (Connector, error) {
c, err := newConfig(cfg)
if err != nil {
return nil, err
Expand Down Expand Up @@ -156,13 +156,6 @@ func newConfig(cf any) (*config.Connector, error) {
}
}

func NewConnectorWithLoggers(configPath string, mapper Mapper, logrus *logrus.Logger) (Connector, error) {
logger.Log = &logger.Loggers{
Logrus: logrus,
}
return NewConnector(configPath, mapper)
}

func createKafkaClient(cc *config.Connector) (kafka.Client, error) {
kafkaClient := kafka.NewClient(cc)

Expand Down Expand Up @@ -205,3 +198,31 @@ func newConnectorConfigFromPath(path string) (*config.Connector, error) {
c.ApplyDefaults()
return &c, nil
}

type ConnectorBuilder struct {
mapper Mapper
config any
}

func NewConnectorBuilder(config any) ConnectorBuilder {
return ConnectorBuilder{
config: config,
mapper: DefaultMapper,
}
}

func (c ConnectorBuilder) SetMapper(mapper Mapper) ConnectorBuilder {
c.mapper = mapper
return c
}

func (c ConnectorBuilder) Build() (Connector, error) {
return newConnector(c.config, c.mapper)
}

func (c ConnectorBuilder) SetLogger(l *logrus.Logger) ConnectorBuilder {
logger.Log = &logger.Loggers{
Logrus: l,
}
return c
}
22 changes: 22 additions & 0 deletions example/default-mapper/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.19-alpine as builder

WORKDIR /project

COPY go.mod go.sum ./
COPY main.go ./
COPY config.yml ./config.yml

RUN go mod download
RUN CGO_ENABLED=0 go build -a -o example main.go

FROM alpine:3.17.0

WORKDIR /app

RUN apk --no-cache add ca-certificates

USER nobody
COPY --from=builder --chown=nobody:nobody /project/example .
COPY --from=builder --chown=nobody:nobody /project/config.yml ./config.yml

ENTRYPOINT ["./example"]
32 changes: 32 additions & 0 deletions example/default-mapper/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
hosts:
- localhost:8091
username: user
password: password
bucketName: dcp-test
scopeName: _default
collectionNames:
- _default
metadata:
type: couchbase
config:
bucket: checkpoint-bucket-name
scope: _default
collection: _default
dcp:
group:
name: groupName
membership:
type: static
kafka:
collectionTopicMapping:
_default: topicname
brokers:
- localhost:9092
# SSL configurations
#
# secureConnection: true
# Config support env variable "$HOME/example/..."
# rootCAPath: "example/stretch-kafka/rootCA.pem"
# interCAPath: "example/stretch-kafka/interCA.pem"
# scramUsername: "username"
# scramPassword: "password"
78 changes: 78 additions & 0 deletions example/default-mapper/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module example

go 1.19

replace github.com/Trendyol/go-dcp-kafka => ./../..

require github.com/Trendyol/go-dcp-kafka v0.0.0

require (
github.com/Trendyol/go-dcp v1.0.0 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.6.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/couchbase/gocbcore/v10 v10.2.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gofiber/adaptor/v2 v2.1.31 // indirect
github.com/gofiber/fiber/v2 v2.48.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mhmtszr/concurrent-swiss-map v0.0.9 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/segmentio/kafka-go v0.4.42 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.48.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.27.4 // indirect
k8s.io/apimachinery v0.27.4 // indirect
k8s.io/client-go v0.27.4 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 33db364

Please sign in to comment.