继续关于Kafka文档的阅读
This commit is contained in:
@@ -137,4 +137,91 @@ Topic:my-replicated-topic PartitionCount:1 ReplicationFactor:3 Configs:
|
|||||||
```
|
```
|
||||||
对于每个分区,leader都是随机选择的,并且,在leader宕机之后会有一台从机自动的成为leader
|
对于每个分区,leader都是随机选择的,并且,在leader宕机之后会有一台从机自动的成为leader
|
||||||
|
|
||||||
|
## APIS
|
||||||
|
Kafka包含5个核心api:
|
||||||
|
1. Producer API:允许应用向Kafka集群的Topic发送stream数据
|
||||||
|
2. Consumer API:允许应用丛Kafka集群的Topic中读取数据
|
||||||
|
3. Streams API:允许在input topic和output topic之间传递stream数据
|
||||||
|
4. Connect API:允许实现连接器,连接器会不断从源系统或应用拉拉取数据到Kafka或从Kafka推送数据到系统或者应用
|
||||||
|
5. Admin API:允许管理和查看topic,broker和其他Kafka对象
|
||||||
|
|
||||||
|
### Producer API
|
||||||
|
要使用Producer API,需要添加如下maven依赖:
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.kafka</groupId>
|
||||||
|
<artifactId>kafka-clients</artifactId>
|
||||||
|
<version>2.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
### Consumer API
|
||||||
|
要使用Consumer API,需要添加如下maven依赖:
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.kafka</groupId>
|
||||||
|
<artifactId>kafka-clients</artifactId>
|
||||||
|
<version>2.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
### Stream API
|
||||||
|
要使用Stream API,需要添加如下maven依赖:
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.kafka</groupId>
|
||||||
|
<artifactId>kafka-streams</artifactId>
|
||||||
|
<version>2.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
### Admin API
|
||||||
|
要使用Admin API,需要添加如下maven依赖:
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.kafka</groupId>
|
||||||
|
<artifactId>kafka-clients</artifactId>
|
||||||
|
<version>2.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
### Broker Configs
|
||||||
|
基础的配置如下:
|
||||||
|
- broker.id
|
||||||
|
- log.dirs
|
||||||
|
- zookeeper
|
||||||
|
> zookeeper.connect
|
||||||
|
> 通过`hostname:port`以字符串的形式来指定zookeeper连接,hostname和port为zookeeper server对应的域名和端口。如果要指定zookeeper集群,可以通过`hostname1:port1,hostname2:port2,hostname3:port3`的形式来指定多个hosts。
|
||||||
|
|
||||||
|
#### Broker Configs 动态更新
|
||||||
|
从Kafka版本1.1往后,一些broker config可以被更新而不需要重启broker。可以在`Broker Config`条目的`Dynamic Update Mode`栏查看是否该config栏是否允许动态更新:
|
||||||
|
- read-only:如果要更新该条目,需要重新启动broker
|
||||||
|
- per-broker:可以对每个broker进行动态更新
|
||||||
|
- cluster-wide:可以在集群的范围内进行动态更新
|
||||||
|
|
||||||
|
如下命令会修改broker 0的配置:
|
||||||
|
```shell
|
||||||
|
> bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-name 0 --alter --add-config log.cleaner.threads=2
|
||||||
|
```
|
||||||
|
如下命令会返回broker 0的动态配置:
|
||||||
|
```shell
|
||||||
|
> bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-name 0 --describe
|
||||||
|
```
|
||||||
|
如果要删除一个覆盖的配置并且将配置值回滚为静态配置或者默认值,可以使用如下命令:
|
||||||
|
```shell
|
||||||
|
> bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-name 0 --alter --delete-config log.cleaner.threads
|
||||||
|
```
|
||||||
|
一些配置可以设置为集群默认的配置,在整个集群中都维护为一致的值。集群中所有的broker都会处理cluster default update,如下命令会更新集群中所有broker的log cleaner threads:
|
||||||
|
```shell
|
||||||
|
> bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-default --alter --add-config log.cleaner.threads=2
|
||||||
|
```
|
||||||
|
通过如下命令可以输出集群范围内的默认配置:
|
||||||
|
```shell
|
||||||
|
> bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-default --describe
|
||||||
|
```
|
||||||
|
所有可以在集群层面配置的条目都可以针对单个broker配置。如果一个条目在多个条目都有配置,那么会按照如下优先级:
|
||||||
|
- 存储在zookeeper中的针对单个broker的配置
|
||||||
|
- 存储在zookeeper中的针对集群的配置
|
||||||
|
- server.properties中静态配置的条目
|
||||||
|
- Kafka的默认值
|
||||||
|
|
||||||
|
#### 动态更新Password Configs
|
||||||
|
动态更新的password config值在存储到zookeeper之前会被加密。
|
||||||
Reference in New Issue
Block a user