To install Kafka package, you need to install Go and set your Go workspace first.
- You first need Go installed (version 1.18+ is required), then you can use the below Go command to install Kafka.
$ go get -u github.com/confluentinc/confluent-kafka-go/kafka
- Import it in your code:
import "github.com/confluentinc/confluent-kafka-go/kafka"
- You first need Makefile
# install windows
C:\> choco install make
# install linux
$ sudo apt-get install make
# install MacOS with Homebrew
$ brew install make
# verify that Makefile is installed correctly by checking the version
$ make --version
-
You first need Docker Desktop installed.
-
You first need Docker Compose.
- Docker Compose is included in Docker Desktop for Windows and macOS.
- For Ubuntu and Debian, run:
$ sudo apt-get update
$ sudo apt-get install docker-compose-plugin
- For RPM-based distros, run:
$ sudo yum update
$ sudo yum install docker-compose-plugin
# verify that Docker Compose is installed correctly by checking the version
$ docker compose version
- You first need Kafka CLI or Web UI
# install kafka cli, make sure all container running
$ make compose
# install kafka web ui, make sure all container running, wait 1 minutes, then open to browser http://localhost:9021
$ make compose-ui
- Producer
# application producer, run:
$ make producer
- Consumer
# application consumer1, run:
$ make consumer1
# application consumer2, run:
$ make consumer2
Note that you need to set the corresponding binding tag on Operating System. For example: winpty
, sudo
or etc
# entry into docker container kafka, run:
$ make exec
$ kafka-topics --bootstrap-server localhost:9092 --create --topic YOURTOPIC
$ kafka-topics --bootstrap-server localhost:9092 --create --topic YOURTOPIC --replication-factor 1 --partitions 3 --config "cleanup.policy=compact" --config "delete.retention.ms=100" --config "segment.bytes=204800" --config "min.cleanable.dirty.ratio=0.01"
$ kafka-topics --bootstrap-server localhost:9092 --list
$ kafka-topics --bootstrap-server localhost:9092 --delete --topic YOURTOPIC
$ kafka-topics --bootstrap-server localhost:9092 --alter --topic YOURTOPIC --partitions 3
$ kafka-topics --bootstrap-server localhost:9092 --describe --topic YOURTOPIC
$ kafka-console-producer --bootstrap-server localhost:9092 --topic YOURTOPIC
# example: >1:test
$ kafka-console-producer --bootstrap-server localhost:9092 --topic YOURTOPIC --property "parse.key=true" --property "key.separator=:"
$ kafka-console-consumer --bootstrap-server localhost:9092 --topic YOURTOPIC --from-beginning
$ kafka-console-consumer --bootstrap-server localhost:9092 --topic YOURTOPIC --group YOURGROUP --from-beginning
$ kafka-console-consumer --bootstrap-server localhost:9092 --topic YOURTOPIC --group YOURGROUP --from-beginning --property "print.key=true"
$ kafka-consumer-groups --bootstrap-server localhost:9092 --all-groups --all-topics --describe
$ kafka-consumer-groups --bootstrap-server localhost:9092 --group YOURGROUP --describe