常用的 Kafka 相关操作命令:
启动 ZooKeeper 服务器:
bin/zookeeper-server-start.sh config/zookeeper.properties
启动 Kafka 服务器:
bin/kafka-server-start.sh config/server.properties
创建一个主题(topic):
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic my-topic
其中,–replication-factor指定副本数量,–partitions指定分区数量,–topic指定主题名称。
查看主题列表:
bin/kafka-topics.sh --list --zookeeper localhost:2181
生产者发送消息:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-topic
消费者消费消息:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-beginning
其中,–bootstrap-server指定 Kafka 服务器地址,–from-beginning指定从最早的消息开始消费。
查看主题详情:
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-topic
修改主题配置:
bin/kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name my-topic --alter --add-config max.message.bytes=64000
其中,–add-config指定要修改的配置,max.message.bytes指定消息最大字节数