Go Redis Kafka Demo
A demo application that interacts with Kafka (producer & consumer) + Redis
This application has 2 parts
- http-server
- kafka-consumer
The http-server handles 2 routes
- http://127.0.0.1:8080/produce - this produces an event on kafka of the shape
{ type: "number", number: 123333 }
the kafka-consumer listens to this event and determines whether the number is odd/even and based on that increments (incr
) a key in redis
- http://127.0.0.1:8080/ - gives you statistics like
{"requests":12,"even":5,"odd":7}
number of events/requests processed so far, number of odd numbers, number of even numbers
To run this project
Directly
https://github.com/khan019950/go-redis-kafka-docker-demo.git
- Install go & setup your development environment
- Install Redis
- Install Kafka & make a topic call
numbers
(you can name the topic something else also; but make sure the name of the topic is correct in start.sh
)
- RUN
./start.sh
the start.sh
contains enviroment variables you need to handle it according to you convinence
With Docker
How to create docker image with Dockerfile ?
docker build -f <PATH-TO-DOCKERFILE> -t <DOCKER-REGISTRY>/go-redis-kafka-demo:<VERSION-NUMBER>-alpine .
docker push <DOCKER-REGISTRY>/go-redis-kafka-demo:<VERSION-NUMBER>-alpine
How to use docker-compose file ?
docker-compose files assumes following values for variables:
- go server exposed port is
8080
- docker image of go-server is
go-redis-kafka-demo:1.0-alpine
- redis host and port is
redis:6379
- kafka host and port is
kafka:9092
- kafka topic name is
numbers
- redis and kafka will be mounted to relative paths in current directory of compose file.
NOTE: You can change values of above variables if you want, just update them properly in docker-compose file
There are 2 compose files:
docker-compose.yml
will setup redis, kafka and zookeeper where only kafka and redis will exposed on bridge network.
docker-compose-all-in-one.yml
will setup redis, kafka, zookeeper and go-server where only port of go-server will be exposed to bridge network
compose file usage:
- To setup infra:
docker-compose -f <PATH-TO-COMPOSE-FILE> up -d
- To destory:
docker-compose -f <PATH-TO-COMPOSE-FILE> down