比如,我们给kafka的topic命名为user_r2p10
表示user这个topic的副本因子(r)是2,分区数(p)是10。
这样后期在写消费者代码的时候,根据topic名称就知道分区有多少个,可以很方便的设置多少个消费者线程。
比如,如下
前期博客,见
Kafka的3节点集群详细启动步骤(Zookeeper是外装)
然后,
创建topic
[hadoop@master kafka_2.10-0.9.0.1]$ pwd /home/hadoop/app/kafka_2.10-0.9.0.1 [hadoop@master kafka_2.10-0.9.0.1]$ ll total 128 drwxr-xr-x 3 hadoop hadoop 4096 Jul 27 17:56 bin drwxr-xr-x 2 hadoop hadoop 4096 Jul 27 19:16 config -rw-rw-r-- 1 hadoop hadoop 19520 Jul 28 19:57 kafka.log drwxr-xr-x 2 hadoop hadoop 4096 Jul 27 17:26 libs -rw-r--r-- 1 hadoop hadoop 11358 Feb 12 2016 LICENSE drwxrwxr-x 2 hadoop hadoop 4096 Jul 28 19:56 logs -rw------- 1 hadoop hadoop 67054 Jul 27 23:28 nohup.out -rw-r--r-- 1 hadoop hadoop 162 Feb 12 2016 NOTICE drwxr-xr-x 2 hadoop hadoop 4096 Feb 12 2016 site-docs [hadoop@master kafka_2.10-0.9.0.1]$ bin/kafka-topics.sh --zookeeper master:2181,slave1:2181,slave2:2181 --create --topic gold_log_r2p5 --replication-factor 2 --partitions 5 WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both. Created topic "gold_log_r2p5". [hadoop@master kafka_2.10-0.9.0.1]$ [hadoop@master kafka_2.10-0.9.0.1]$
本文转自大数据躺过的坑博客园博客,原文链接:http://www.cnblogs.com/zlslch/p/7246749.html,如需转载请自行联系原作者