kafka

1、下载kafka安装包

http://kafka.apache.org/downloads

2、启动zookeeper

​ windows版,尝试在\bin\windows目录下建start_zookeeper.bat内容为:zookeeper-server-start.bat ../../config/zookeeper.properties

​ 在cmd中输入文件名,即可启动

3、启动kafka

​ windows版,尝试在\bin\windows目录下建start_kafka.bat内容为:kafka-server-start.bat ../../config/server.properties

​ 在cmd中输入文件名,即可启动

4、创建一个topic主题

命令:请在kafka-topics.bat所在的目录执行命令

kafka-topics.bat --zookeeper localhost:2181 --create --topic xw-topic --replication-factor 1 --partitions 8

5、查询topic列表

​ kafka-topics.bat --zookeeper localhost:2181 --list

6、删除topic

​ 命令:kafka-topics.bat --delete --zookeeper localhost:2181 --topic xw-topic

​ 由于server.properties中没有配置delete.topic.enable=true。故只是标记为删除

Topic xw-topic is marked for deletion.

Note: This will have no impact if delete.topic.enable is not set to true.

7、扩展topic分区

kafka-topics.bat --zookeeper localhost:2181 --alter --topic xw-topic --partitions 16

由之前的分区,变成16个分区了,貌似不能变成8个分区了

8、查询topic和它的分区的详细信息

kafka-topics.bat --zookeeper localhost:2181 --describe

Topic:xw-topic  PartitionCount:16       ReplicationFactor:1     Configs:
        Topic: xw-topic Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 1    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 2    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 3    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 4    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 5    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 6    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 7    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 8    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 9    Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 10   Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 11   Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 12   Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 13   Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 14   Leader: 0       Replicas: 0     Isr: 0
        Topic: xw-topic Partition: 15   Leader: 0       Replicas: 0     Isr: 0
9、kafka的基本消费者和生产者的命令敲击

kafka-console-producer.bat --broker-list localhost:9092 --topic my-topic

10、linux kafka 后台启动
./kafka-server-start.sh -daemon ../config/server.properties