Monday 11 November 2019

Kafka CLI: commands cheetsheet


Description
Syntax
Example
Create Topic
kafka-topics.sh --bootstrap-server {bootStratServerDetails} --topic {topicName} --create --partitions {numberOfPartitions} --replication-factor {replicationFactor}
kafka-topics.sh --bootstrap-server localhost:9092 --topic myFirstTopic --create --partitions 3 --replication-factor 1
Describe topic
kafka-topics.sh --bootstrap-server {bootStratServerDetails} --topic {topicName} --describe
kafka-topics.sh --bootstrap-server localhost:9092 --topic myFirstTopic --describe
Delete topic
kafka-topics.sh --bootstrap-server {bootStrapServerDetails} --topic mySecondTopic --delete
kafka-topics.sh --bootstrap-server localhost:9092 --topic mySecondTopic --delete
List all topics
kafka-topics.sh --bootstrap-server {bootStrapServerDetails} --list
kafka-topics.sh --bootstrap-server localhost:9092 --list
Send message to kafka topic
kafka-console-producer.sh --broker-list {kafkaServiceDetails} --topic {topicName}
kafka-console-producer.sh --broker-list localhost:9092 --topic myFirstTopic
Send additional properties to a message
kafka-console-producer.sh --broker-list {kafkaServiceDetails} --topic {topicName} --producer-property {prop1}={value1} {prop2}={value2}
kafka-console-producer.sh --broker-list localhost:9092 --topic myFirstTopic --producer-property acks=1
Consume messages from a topic
kafka-console-consumer --bootstrap-server {serverDetails}--topic {topicName}
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic myFirstTopic
Consume all messages from topic (beginning of topic)
kafka-console-consumer --bootstrap-server {serverDetails}--topic {topicName} --from-beginning
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic myFirstTopic --from-beginning
Add a consumer to group
kafka-console-consumer --bootstrap-server {serverDetails}--topic {topicName} --group {groupName}
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic myFirstTopic --group myFirstConsumerGroup
Print all consumer groups
kafka-consumer-groups.sh --bootstrap-server {serverDetails} --list
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
Describe consumer group
kafka-consumer-groups.sh --bootstrap-server {serverDetails} --describe --group {groupName}
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group myFirstConsumerGroup
Reset Offsets
kafka-consumer-groups.sh --bootstrap-server {serverDetails} --group {groupName} --reset-offsets --to-earliest --execute --topic {topicName}
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group myFirstConsumerGroup --reset-offsets --to-earliest --execute --topic myFirstTopic
Get kafka version
kafka-topics.sh --version
kafka-topics.sh --version




Previous                                                    Next                                                    Home

No comments:

Post a Comment