Skip to content

Commit

Permalink
feat: add dummy consumer for example
Browse files Browse the repository at this point in the history
  • Loading branch information
achoimet committed Nov 8, 2024
1 parent e640c34 commit 6429608
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,32 @@ jobs:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
VERSION_BUMPER_SECRET: ${{ secrets.GH_APP_STEADYBIT_PRIVATE_KEY }}
GCP_ARTIFACT_REGISTRY_IDENTITY_PROVIDER: ${{ secrets.GCP_ARTIFACT_REGISTRY_IDENTITY_PROVIDER }}

build-consumer-image:
name: Build Dummy Consumer Image
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: ./test-dataset/dummyconsumer/
file: ./test-dataset/dummyconsumer/Dockerfile
push: true
tags: steadybit/extension-kafka/dummyconsumer:latest
19 changes: 19 additions & 0 deletions test-dataset/dummyconsumer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.23 AS builder

WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o myapp

FROM alpine:3.14

ARG USERNAME=steadybit
ARG USER_UID=10000

RUN adduser -u $USER_UID -D $USERNAME

USER $USERNAME

WORKDIR /app
COPY --from=builder /app/myapp /app/

CMD ["/app/myapp"]
17 changes: 17 additions & 0 deletions test-dataset/dummyconsumer/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/steadybit/extension-kafka/dummyconsummer

go 1.23.0

require (
github.com/rs/zerolog v1.33.0
github.com/twmb/franz-go v1.18.0
)

require (
github.com/klauspost/compress v1.17.8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.9.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)
25 changes: 25 additions & 0 deletions test-dataset/dummyconsumer/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/twmb/franz-go v1.18.0 h1:25FjMZfdozBywVX+5xrWC2W+W76i0xykKjTdEeD2ejw=
github.com/twmb/franz-go v1.18.0/go.mod h1:zXCGy74M0p5FbXsLeASdyvfLFsBvTubVqctIaa5wQ+I=
github.com/twmb/franz-go/pkg/kmsg v1.9.0 h1:JojYUph2TKAau6SBtErXpXGC7E3gg4vGZMv9xFU/B6M=
github.com/twmb/franz-go/pkg/kmsg v1.9.0/go.mod h1:CMbfazviCyY6HM0SXuG5t9vOwYDHRCSrJJyBAe5paqg=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
40 changes: 34 additions & 6 deletions test-dataset/dummyconsumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,49 @@ import (
"github.com/rs/zerolog/log"
"github.com/twmb/franz-go/pkg/kgo"
"github.com/twmb/franz-go/pkg/sasl/plain"
"os"
"strings"
)

func main() {
seeds := []string{"localhost:9092"}
// Configure
seeds, _ := os.LookupEnv("STEADYBIT_DUMMY_SEED_BROKERS")
if seeds == "" {
seeds = "kafka-demo.steadybit-demo.svc.cluster.local:9092"
}

saslUser, _ := os.LookupEnv("STEADYBIT_DUMMY_SASL_USER")
if saslUser == "" {
saslUser = "user1"
}

saslPassword, _ := os.LookupEnv("STEADYBIT_DUMMY_SASL_PASSWORD")
if saslPassword == "" {
saslPassword = "steadybit"
}

topic, _ := os.LookupEnv("STEADYBIT_DUMMY_TOPIC")
if topic == "" {
topic = "steadybit-demo"
}

consumer, _ := os.LookupEnv("STEADYBIT_DUMMY_CONSUMER_NAME")
if consumer == "" {
consumer = "steadybit-demo-consumer"
}

// One client can both produce and consume!
// Consuming can either be direct (no consumer group), or through a group. Below, we use a group.
cl, err := kgo.NewClient(
kgo.SeedBrokers(seeds...),
kgo.ConsumerGroup("dummy"),
kgo.ConsumeTopics("steadybit"),
kgo.SeedBrokers(strings.Split(seeds, ",")...),
kgo.ConsumerGroup(consumer),
kgo.ConsumeTopics(topic),
kgo.SASL(plain.Auth{
User: "consumer",
Pass: "consumer-secret",
User: saslUser,
Pass: saslPassword,
}.AsMechanism()),
)
log.Info().Msgf("Initiating consumer with kafka config: brokers %s, consumer name %s on topic %s with user %s", seeds, consumer, topic, saslUser)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 6429608

Please sign in to comment.