命令行方式
- 创建一个主题
[root@manager129 kafka_2.12-2.8.0]# ./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic heima -partitions 2 --replication-factor 1
Created topic heima.
- zookeeper: 指定kafka所连接的zookeeper服务地址
- topic:指定了所要创建的主题
- partitions:制定了分区个数
- replication-factor:指定了副本因子
- create:创建主题的动作指令
- 展示所有主题
命令:
[root@manager129 kafka_2.12-2.8.0]# ./bin/kafka-topics.sh --zookeeper localhost:2181 --list
heima
- 查看主题详情
命令:
[root@manager129 kafka_2.12-2.8.0]# ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic heima
Topic: heima TopicId: D0rctcUJQ-2-1QstiUHw6w PartitionCount: 2 ReplicationFactor: 1 Configs:
Topic: heima Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: heima Partition: 1 Leader: 0 Replicas: 0 Isr: 0
- 启动消费者服务
命令:
[root@manager129 kafka_2.12-2.8.0]# ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic heima
> hello
- 启动生产者服务
命令:
[root@manager129 kafka_2.12-2.8.0]# ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic heima
>hello