包虫病

注册

 

发新话题 回复该主题

Kafka调试入门一 [复制链接]

1#
Kafka调试入门(一)温习

很多人对kafka消息队列应该不陌生,使用起来也比较方便。对kafka最常见的操作一般有如下几种:

启动kafka集群创建一个名称为xxx的主题(topic)查看已经创建好的主题向xxx这个主题中插入一些数据从xxx这个主题中消费一些数据

针对这几种操作,其实kafka都为大家提供了一系列方便使用的脚本,这些脚本都在bin文件夹中,主要有:

bin/kafka-server-start.sh//作用是启动kafka服务端进程bin/kafka-topics.sh//作用是创建、查看主题bin/kafka-console-producer.sh//命令行方式的生产者bin/kafka-console-consumer.sh//命令行方式的消费者

下面是一些常用的操作实例:

启动kafka集群:

bin/kafka-server-start.shconfig/server.properties

创建一个名称是test的主体(topic)

bin/kafka-topics.sh--create--zookeeperlocalhost:--replication-factor1--partitions1--topictest

查看创建的主题(topic)

bin/kafka-topics.sh--list--zookeeperlocalhost/p>往test这个topic中插入一些数据,用kafka-console-producer

bin/kafka-console-producer.sh--broker-listlocalhost:--topictest

从test这个topic中消费一些数据,用kafka-console-consumer从最开头开始读取数据:

bin/kafka-console-consumer.sh--bootstrap-serverlocalhost:--topictest--from-beginning

2正文

《kafka-server-start.sh执行流程分析》

首先分析一下运行

bin/kafka-server-start.shconfig/server.properties

的时候,kafka源码的执行流程。

第一步:先看看kafka-server-start.sh这个脚本,如下:

#!/bin/bash#LicensedtotheApacheSoftwareFoundation(ASF)underoneormore#contributorlicenseagreements.SeetheNOTICEfiledistributedwith#thisworkforadditionalinformationregardingcopyrightownership.#TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0#(the"License");youmaynotusethisfileexceptin

分享 转发
TOP
发新话题 回复该主题