diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4aab61d --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +run-kafka: + @docker exec -it fc2-kafka-kafka-1 bash diff --git a/README.md b/README.md new file mode 100644 index 0000000..8229796 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# Kafka basics and commands +Prerequisite: make sure the Kafka broker is running and reachable at localhost:9092. + +## How to read the diagram (kafka.png) +![Kafka overview](./kafka.png) + +## Delivery +![Kafka delivery overview](./delivery.png) +# Commands + +## Topics +- Create a topic (3 partitions): +```shell +kafka-topics --create --topic test --bootstrap-server localhost:9092 --partitions 3 +``` +- List all topics: +```shell +kafka-topics --list --bootstrap-server localhost:9092 +``` +- Describe a topic (partitions/replicas/leader): +```shell +kafka-topics --describe --topic test --bootstrap-server localhost:9092 +``` +- Delete a topic: +```shell +kafka-topics --delete --topic test --bootstrap-server localhost:9092 +``` + +## Console Producer +- Write messages from stdin to a topic. Each line you type is a message: +```shell +kafka-console-producer --topic test --bootstrap-server localhost:9092 +``` + +## Console Consumer +- Read new messages from the tip of the log: +```shell +kafka-console-consumer --topic test --bootstrap-server localhost:9092 +``` +- Read everything from the beginning of the topic: +```shell +kafka-console-consumer --topic test --bootstrap-server localhost:9092 --from-beginning +``` +- Join a consumer group (enables scaling and offset tracking): +```shell +kafka-console-consumer --topic test --bootstrap-server localhost:9092 --group group-x +``` + +## Consumer Groups +- Describe a group (lags, offsets, assignments). Start at least one consumer in the group first: +```shell +kafka-consumer-groups --bootstrap-server localhost:9092 --group group-x --describe +``` diff --git a/delivery.png b/delivery.png new file mode 100644 index 0000000..79fcd5a Binary files /dev/null and b/delivery.png differ diff --git a/docker-compose.yaml b/docker-compose.yaml index 47d4f75..0eba2db 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,4 @@ -version: "3" - -services: - +services: zookeeper: image: confluentinc/cp-zookeeper:latest environment: diff --git a/kafka.png b/kafka.png new file mode 100644 index 0000000..bda27b1 Binary files /dev/null and b/kafka.png differ