当前位置:K88软件开发文章中心大数据Apache Kafka → 文章内容

Apache Kafka 基本操作

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-26 10:04:49

Partition:0 Leader:0 Replicas:0,2,1 Isr:0,2,1从上面的输出,我们可以得出结论,第一行给出所有分区的摘要,显示主题名称,分区数量和我们已经选择的复制因子。 在第二行中,每个节点将是分区的随机选择部分的领导者。在我们的例子中,我们看到我们的第一个broker(with broker.id 0)是领导者。 然后Replicas:0,2,1意味着所有代理复制主题最后 Isr 是 in-sync 副本的集合。 那么,这是副本的子集,当前活着并被领导者赶上。启动生产者以发送消息此过程保持与单代理设置中相同。示例bin/kafka-console-producer.sh --broker-list localhost:9092 --topic Multibrokerapplication输出bin/kafka-console-producer.sh --broker-list localhost:9092 --topic Multibrokerapplication[2016-01-20 19:27:21,045] WARN Property topic is not valid (kafka.utils.Verifia-bleProperties)This is single node-multi broker demoThis is the second message启动消费者以接收消息此过程保持与单代理设置中所示的相同。示例bin/kafka-console-consumer.sh --zookeeper localhost:2181 —topic Multibrokerapplica-tion --from-beginning输出bin/kafka-console-consumer.sh --zookeeper localhost:2181 —topic Multibrokerapplica-tion —from-beginningThis is single node-multi broker demoThis is the second message基本主题操作在本章中,我们将讨论各种基本主题操作。修改主题您已经了解如何在Kafka Cluster中创建主题。 现在让我们使用以下命令修改已创建的主题语法bin/kafka-topics.sh —zookeeper localhost:2181 --alter --topic topic_name --parti-tions count示例We have already created a topic “Hello-Kafka" with single partition count and one replica factor. Now using “alter" command we have changed the partition count.bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic Hello-kafka --parti-tions 2输出WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affectedAdding partitions succeeded!删除主题要删除主题,可以使用以下语法。语法bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic topic_name示例bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic Hello-kafka输出> Topic Hello-kafka marked for deletion注意 - 如果 delete.topic.enable 未设置为true,则此操作不会产生任何影响

上一页  [1] [2] 


Apache Kafka 基本操作