Создаем Topic
# /usr/local/kafka-server/bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --replication-factor 1 --partitions 4
Created topic test-topic
Добавляем запись в Топик
# echo "Hello, World" | /usr/local/kafka-server/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic TutorialTopic > /dev/null
Читаем запись из Топика
# /usr/local/kafka-server/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic TutorialTopic --from-beginning
Читаем запись из топика с группой
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning --group test
Hello, World
Смотрим позицию офсета
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test --describe
Consumer group 'test' has no active members.
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
test test-topic 0 0 0 0 - -
test test-topic 1 0 0 0 - -
test test-topic 2 0 0 0 - -
test test-topic 3 1 1 0 - -
Сброс офсета
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test --reset-offsets --to-earliest --topic test-topic --execute
GROUP TOPIC PARTITION NEW-OFFSET
test test-topic 0 0
test test-topic 1 0
test test-topic 2 0
test test-topic 3 0
Посмотреть Топики
# /usr/local/kafka-server/bin/kafka-topics.sh --bootstrap-server=localhost:9092 --list
TutorialTopic
__consumer_offsets
test-topic
topic1
topic2
Посмотреть описание топика
./kafka-topics.sh --describe --topic test-topic --bootstrap-server localhost:9092
Topic: test-topic TopicId: 8xTX3ITdQSerZQ-9XzOzJQ PartitionCount: 4 ReplicationFactor: 1 Configs: segment.bytes=1073741824
Topic: test-topic Partition: 0 Leader: 1001 Replicas: 1001 Isr: 1001
Topic: test-topic Partition: 1 Leader: 1001 Replicas: 1001 Isr: 1001
Topic: test-topic Partition: 2 Leader: 1001 Replicas: 1001 Isr: 1001
Topic: test-topic Partition: 3 Leader: 1001 Replicas: 1001 Isr: 1001
Удалить Топик
# /usr/local/kafka-server/bin/kafka-topics.sh --delete --bootstrap-server=localhost:9092 --topic test-topic