KAFKA基本命令

如下操做基于Linux系统apache

1. 建立一个Topic bootstrap

用一个分区和一个副本建立一个名为“test”的Topic服务器

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testui

 

2. 查看Topic列表server

bin/kafka-topics.sh --list --zookeeper localhost:2181文档

 

3. 发送消息kafka

运行生产者,而后在控制台输入一些消息(以行的形式)发送到服务器,CTRL+C 终止消息的输入it

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testio

 > message 1console

 > message 2

 

4. 查看收到的消息

运行消费者,将消息转储到标准输出

实时显示从最初到如今的消息:bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic test

实时查看消息:bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test

 

5. 查看消费了多少数据

bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper 127.0.0.1:2181 --group hansight --topic event

 

 6. 查看group

./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

 

 7. 导入/导出数据

1)准备一些数据,输出到当前目录下的 test.txt 文件

   echo -e "test_data01\ntest_data02" > test.txt

2)启动两个独立模式运行的链接器

   执行 connect-standalone.sh,携带三个配置文件做为参数:kafka connect过程的配置、建立链接器的配置

      bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties

   第一个链接器:源链接器,用于从输入文件中按行读取数据,并将每一个链接生成为Topic

   第二个链接器:接收器链接器,从Topic中读取消息,并在文件中已行的形式输出消息

   启动后,源链接器开始读取 test.txt,并生成Topic:connect-test;接收器链接器开始读取 connect-test 中的消息,并写入到文件:test.sink.txt

   能够在控制台查看Topic中的数据:bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic connect-test --from-beginning

 

8. 删除Topic

bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic test

若是提示:marked for deletion,则并未真正删除,须要修改配置文件 kafka/config/server.properties,将 delete.topic.enable=false 改成 true,保存后重启kafka,再执行删除命令便可

 

 9. 查看Topic详情

bin/kafka-topics.sh --zookeeper localhost::2181 --topic test --describe

 

参考文档:kafka.apache.org/quickstart   —— kafka官方文档

相关文章
相关标签/搜索