KafkaServer.startup()
kafkaHealthcheck.startup() -> register()
//往zk的某个目录里面写入进去一个注册信息(最重要的注册信息,就是自己的brokerid)
zkUtils.registerBrokerInZk(brokerId, plaintextEndpoint.host, plaintextEndpoint.port, updatedEndpoints, jmxPort, rack,
interBrokerProtocolVersion)
def registerBrokerInZk(id: Int,
host: String,
port: Int,
advertisedEndpoints: collection.Map[SecurityProtocol, EndPoint],
jmxPort: Int,
rack: Option[String],
apiVersion: ApiVersion) {
//构建一个ZK目录
///brokers/ids/0
///brokers/ids/1
///brokers/ids/2
///brokers/ids/3
val brokerIdPath = BrokerIdsPath + "/" + id
val timestamp = SystemTime.milliseconds.toString
val version = if (apiVersion >= KAFKA_0_10_0_IV1) 3 else 2
//封装一些信息
var jsonMap = Map("version" -> version,
"host" -> host,
"port" -> port,
"endpoints" -> advertisedEndpoints.values.map(_.connectionString).toArray,
"jmx_port" -> jmxPort,
"timestamp" -> timestamp
)
rack.foreach(rack => if (version >= 3) jsonMap += ("rack" -> rack))
val brokerInfo = Json.encode(jsonMap)
//直接创建一个/brokers/ids/0 目录,然后往目录里面写进去自己信息
registerBrokerInZk(brokerIdPath, brokerInfo)
info("Registered broker %d at path %s with addresses: %s".format(id, brokerIdPath, advertisedEndpoints.mkString(",")))
}
-> registerBrokerInZk
//也是创建临时目录
val zkCheckedEphemeral = new ZKCheckedEphemeral(brokerIdPath,
brokerInfo,
zkConnection.getZookeeper,
isSecure)
//创建目录
zkCheckedEphemeral.create()
kafka 集群管理-broker注册
最新推荐文章于 2023-04-09 17:36:13 发布