1.3 Quick Start中 Step 3: Create a topic官网剖析(博主推荐)

  一切来源于官网

http://kafka.apache.org/documentation/

 

 

 

 

Step 3: Create a topic
Step 3: 创建一个主题(topic)

 

  Let's create a topic named "test" with a single partition and only one replica:

创建一个名为“test”的Topic,只有一个分区和一个备份:
 
> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

  We can now see that topic if we run the list topic command:

创建好之后,可以通过运行以下命令,查看已创建的topic信息:
> bin/kafka-topics.sh --list --zookeeper localhost:2181
test

  Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

或者,除了手工创建topic外,你也可以配置你的broker,当发布一个不存在的topic时自动创建topic。

 

 

 

  

 

  其实,这个很简单,比如--create就是创建,--list是查看。当然,不能局限于官网,大家要灵活多变,官网只是个参考和引子。

--topic test  名字为test的topic
--partitions 1   分区数为1
--replication-factor 1    复制因子是1(即每个分区在集群中有1份数据)
--zookeeper localhost:2181  这个不多说,太简单

 

 
 

   比如,我们一般写

bin/kafka-topics.sh --create --zookeeper master:2181 --replication-factor 3 --partitions 10 --topic t-behavior

bin/kafka-topics.sh --create --zookeeper hadoop1:2181 --replication-factor 3 --partitions 10 --topic t-behavior
说明:

--replication-factor 3     指定了复制因子3,即每个分区在集群中有3份数据

--partitions  10          指定topic的分区数10
--topic t-behavior       指定创建名为t-behavior的topic

 

 

 

 同时,查看topic详情

bin/kafka-topics.sh --zookeeper txy001:2181 --topic t-behavior --describe
复制代码
打印如下:
Topic:t-behavior  PartitionCount:10       ReplicationFactor:3     Configs:
        Topic: t-behavior Partition: 0    Leader: 1       Replicas: 1,2,0 Isr: 0,1,2
        Topic: t-behavior Partition: 1    Leader: 2       Replicas: 2,0,1 Isr: 0,1,2
        Topic: t-behavior Partition: 2    Leader: 0       Replicas: 0,1,2 Isr: 0,1,2
        Topic: t-behavior Partition: 3    Leader: 1       Replicas: 1,0,2 Isr: 0,1,2
        Topic: t-behavior Partition: 4    Leader: 2       Replicas: 2,1,0 Isr: 0,1,2
        Topic: t-behavior Partition: 5    Leader: 0       Replicas: 0,2,1 Isr: 0,1,2
        Topic: t-behavior Partition: 6    Leader: 1       Replicas: 1,2,0 Isr: 0,1,2
        Topic: t-behavior Partition: 7    Leader: 2       Replicas: 2,0,1 Isr: 0,1,2
        Topic: t-behavior Partition: 8    Leader: 0       Replicas: 0,1,2 Isr: 0,1,2
        Topic: t-behavior Partition: 9    Leader: 1       Replicas: 1,0,2 Isr: 0,1,2
说明;
ReplicationFactor 表示复制因子,即每个分区有几份数据
Leader 分区的主在那个broker上
Replicas 表示分区数据分布在哪些broker上
Isr 表示可立即作为分区的主的broker,即标识3分数据已经保持一致了。
复制代码

 

 


本文转自大数据躺过的坑博客园博客,原文链接:http://www.cnblogs.com/zlslch/p/6766890.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值