feat: keys example

This commit is contained in:
2026-01-25 02:45:30 +00:00
parent 7272016cd2
commit 7c59136cc1
4 changed files with 113 additions and 0 deletions
+19
View File
@@ -52,3 +52,22 @@ If you create more consumers than paritions, the extra consumers will be idle.
There is no scaling down of partitions, to decrease partitions, you need to create a new topic with less partitions and migrate data over.
# 04-keys
If I want to have all messages for a certain user to always go in the same partition, I can use keys.
Example: if messages for the user MUST be processed in order.
Change the container name and the topic
```
sudo chown -R 1000:1000 kafka-data
sudo docker exec kafka-keys /opt/kafka/bin/kafka-topics.sh --create --topic keys-topic --partitions 2 --bootstrap-server localhost:9092
```
If you forget to run the above command to create the topic, the topic will be created automatically when the producer sends the first message. But it will have only 1 partition by default.
DELETE topic:
```
docker exec -it kafka-keys /opt/kafka/bin/kafka-topics.sh --delete --topic keys-topic --bootstrap-server localhost:9092
```