企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**查看创建Topic有哪些参数** ```shell [root@hadoop101 kafka]# bin/kafka-topics.sh --create 要创建一个topic --topic 指定topic的名字 --zookeeper 指定要连接的zookeeper --replication-factor 设置副本因子,这个数值不能大于Broker数量, 即不能大于节点数 --partitions 分区数量 ... ``` **查看当前服务器所有的Topic** ```shell [root@hadoop101 kafka]# bin/kafka-topics.sh --list --zookeeper hadoop101:2181 __consumer_offsets event_attendees events ``` **创建新的Topic** ```shell --topic Topic的名字 --partitions Topic的分区 --replication-factor Topic的副本,如果只有一台服务器则只能设置一个副本 [root@hadoop101 kafka]# bin/kafka-topics.sh --zookeeper hadoop101:2181 --create --topic topicName --partitions 2 --replication-factor 1 Created topic "topicName". ``` **查看某一个Topic的详细信息** ```shell [root@hadoop101 kafka]# bin/kafka-topics.sh --describe --zookeeper hadoop101:2181 --topic topicName Topic:topicName PartitionCount:2 ReplicationFactor:1 Configs: Topic: topicName Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Topic: topicName Partition: 1 Leader: 0 Replicas: 0 Isr: 0 ``` **查看所有Topic的详细信息** ```shell [root@hadoop101 kafka]# bin/kafka-topics.sh --describe --zookeeper hadoop101:2181 Topic:topicName PartitionCount:2 ReplicationFactor:1 Configs: Topic: topicName Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Topic: topicName Partition: 1 Leader: 0 Replicas: 0 Isr: 0 Topic:user_friends PartitionCount:1 ReplicationFactor:1 Configs: Topic: user_friends Partition: 0 Leader: 0 Replicas: 0 Isr: 0 ``` **查看某个Topic下是否有数据** ```shell [root@hadoop101 kafka]# bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list hadoop101:9092 --topic topicName user_friends_raw:0:38204 // 数字大于0则有 user_friends_raw:0:0 // 数字为0则无 ``` **删除某一个Topic** ```shell [root@hadoop101 kafka]# bin/kafka-topics.sh --zookeeper hadoop101:2181 --delete --topic topicName ``` **启动消费者** ```shell --from-beginning 代表从头消费 [root@hadoop101 kafka]# bin/kafka-console-consumer.sh --bootstrap-server hadoop101:9092 --topic topicName --from-beginning ``` **启动生产者** ```shell [root@hadoop101 kafka]# bin/kafka-console-producer.sh --broker-list hadoop101:9092 --topic topicName ```