示例
public static void createTopic(){
String[] optios = new String[]{
"--zookeeper"
,"localhost:2181/kafka"
,"--create"
,"--replication-factor","1"
,"--partitions","1"
,"--topic","topic-create-api"
};
kafka.admin.TopicCommand.main(options);
}
使用这种方式需要添加相关依赖:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>2.0.0</version>
<dependency>
describe使用
优先副本的选举
kafka-perferred-replica-election.sh 脚本中提供了path-to-json-file参数来小批量地对部分分区执行优先副本的选举操作。通过path-to-json-file参数来指定一个JSON文件,这个JSON文件里保存需要执行优先副本选举的分区清单。
- json文件示例:
{
"partitions":[
{
"partition":0,
"topic":"topic-partitions"
},{
"partition":1,
"topic":"topic-partitions"
}
]
}
- 命令
./kafka-preferred-replica-election.sh --zookeeper localhost:2181/kafka --path-to-json-file json.json