Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
feat: add first poc for a Kafka proxy (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya committed Jun 28, 2021
1 parent 0d05272 commit 32263a9
Show file tree
Hide file tree
Showing 22 changed files with 2,080 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Output of the go coverage tool
*.cov

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Binaries of any kind
bin/
47 changes: 47 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- exportloopref
- exhaustive
- forbidigo
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- godot
- gofumpt
- goimports
- revive
- goprintffuncname
- gosec
- gosimple
- govet
- ifshort
- ineffassign
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

linters-settings:
forbidigo:
forbid:
- fmt.Print.* # usually just used for debugging purpose
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.16

WORKDIR /go/src/app
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN make build

EXPOSE 28002
ENTRYPOINT ["./bin/out/app"]
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Makefile based on https://gist.github.com/thomaspoignant/5b72d579bd5f311904d973652180c705

GOCMD=go
GOTEST=$(GOCMD) test
PROJECT_NAME := $(shell basename "$(PWD)")
BINARY_NAME?=$(PROJECT_NAME)
BIN_DIR?=bin
TOOLS_DIR?=bin/tools

GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)

GOLANGCILINT_VERSION = 1.40.1

.PHONY: all test build vendor

all: help

## Build:
build: ## Build your project and put the output binary in bin/out
mkdir -p $(BIN_DIR)
$(GOCMD) build -o bin/out/$(BINARY_NAME) .

## Linting:
lint: $(TOOLS_DIR)/golangci-lint ## Run linters
$(TOOLS_DIR)/golangci-lint run

## Test:
test: ## Run the tests of the project
$(GOTEST) -v -race ./...

coverage: ## Run the tests of the project and export the coverage
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
$(GOCMD) tool cover -func profile.cov

## Help:
help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)
$(BIN_DIR):
mkdir -p $(BIN_DIR)

$(TOOLS_DIR):
mkdir -p $(TOOLS_DIR)

$(TOOLS_DIR)/golangci-lint: $(TOOLS_DIR)
@wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | BINDIR=$(@D) sh -s v$(GOLANGCILINT_VERSION) > /dev/null 2>&1
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
version: "3.5"

services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
hostname: zookeeper
container_name: zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181

broker:
image: confluentinc/cp-kafka:latest
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "9092:9092" # external connection
environment:
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_LOG4J_ROOT_LOGLEVEL: ERROR
KAFKA_LOG4J_LOGGERS: 'KafkaRequestHandler=TRACE,kafka.server.KafkaApis=TRACE,kafka.log.Log=TRACE,kafka.network.RequestChannel=TRACE,kafka.network.Processor=TRACE'

proxy:
hostname: proxy
container_name: proxy
build:
context: .
dockerfile: Dockerfile
environment:
EVENTGATEWAY_KAFKA_PROXY_BROKERS_MAPPING: 'localhost:9092,proxy:28002'
EVENTGATEWAY_KAFKA_PROXY_BROKERS_DIAL_MAPPING: 'localhost:9092,broker:9092'
EVENTGATEWAY_DEBUG: 'true'
depends_on:
- broker
25 changes: 25 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module github.com/asyncapi/event-gateway

go 1.16

require (
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21
github.com/frankban/quicktest v1.11.3 // indirect
github.com/grepplabs/kafka-proxy v0.2.8
github.com/kelseyhightower/envconfig v1.4.0
github.com/klauspost/compress v1.12.2
github.com/kr/text v0.2.0 // indirect
github.com/pierrec/lz4 v2.6.0+incompatible
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0 // indirect
github.com/xdg/scram v1.0.3 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/net v0.0.0-20210427231257-85d9c07bbe3a // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/grepplabs/kafka-proxy => github.com/smoya/kafka-proxy v0.2.9-0.20210623125118-a94cf71a065c

0 comments on commit 32263a9

Please sign in to comment.