This project is used to produce protobuf messages message to given kafka topic
- Integration testing
- Debugging
- Mocking proto messages
- able to register protobug using proto-descriptor - one time
- able to discover all register protobuf message
- able to convert json to protobuf message dynamically, and send protobuf message to given topic
-
Clone the repository into any folder/workspace you want
-
Step 1 : run the below shell-script to generate proto descriptor.pb file
./gen-proto.sh
make sure to run it form the directory that contain ./proto folder
-
Verify the file : proto/descriptor.pb should be generated to the respective folder
-
run
go build
-
run
./kafka-protobuf-producer
orgo run main.go
go test ./...
curl -X GET localhost:8080/protos
curl -X GET localhost:8080/protos/:protoNameFromAboveResponse/describe
curl -d '{"data": "eyJyZWNvcmRJZCI6IjAwMSIsICJjcmVhdGVkQXQiOiIyMDIxLTEyLTAyVDAwOjAwOjAwWiIsInVwZGF0ZWRCeSI6ICJuZWVyYWoifQ=="}' \
-H "Content-Type: application/json" \
-H "X-Proto-Message-Type: Record.proto" \
-X POST localhost:8080/produces/:topicName
Note: data is base64 encoded json string
Make sure protifile name and message name should be same - sake of simplicity
HEADER_NAME | Description | Mandatory? |
---|---|---|
X-Proto-Message-Type | name of the proto to be used to produce message | if missing - produces pain/text |
echo -ne \
"{\"recordId\":\"001\", \"createdAt\":\"2021-12-02T00:00:00Z\",\"updatedBy\": \"neeraj\"}" | base64
Configuration is read from following environment variables
Variable | Description | Default Value | Possible Values |
---|---|---|---|
BOOTSTRAP_SERVER | kafka bootstrap server | localhost:9092 | host post |
ACKS | number of acks required | 1 | 1,2,all |
CLIENT_ID | client id | golang-clientid | optional - keep default |
PROTO_DESC_PATH | file path for descriptor.pb | ./proto/descriptor.pb | filepath (volume mount) |
docker build -t needubey/kafka-proto-producer:latest .
docker run --rm -it --name kafka-proto-producer \
-p 8080:8080 \
-e PROTO_DESC_PATH=/proto/descriptor.pb \
-v /proto:/proto \
needubey/kafka-proto-producer
Server is exposed on container port 8080