Apache kafka Kakfa 2.4中的TopicCommand.alterTopic

Apache kafka Kakfa 2.4中的TopicCommand.alterTopic,apache-kafka,Apache Kafka,我有一个老项目(它不是我的),我正在尝试将它从卡夫卡2.1更新到2.4 我有下面的代码 public synchronized void increasePartitions(字符串主题,int分区)引发InvalidPartitionsException、IllegalArgumentException{ StringBuilder commandString=新建StringBuilder(); 追加(“--alter”); commandString.append(“--topic”).a

我有一个老项目(它不是我的),我正在尝试将它从卡夫卡2.1更新到2.4

我有下面的代码

public synchronized void increasePartitions(字符串主题,int分区)引发InvalidPartitionsException、IllegalArgumentException{
StringBuilder commandString=新建StringBuilder();
追加(“--alter”);
commandString.append(“--topic”).append(topic);
commandString.append(“--zookeeper”).append(config.getOrDefault(“zookeeper.connect”),
“本地主机:2181”);
append(“--partitions”).append(分区);
String[]command=commandString.toString().split(“”);
TopicCommand.alterTopic(kafkaZkClient,新的TopicCommand.TopicCommandOptions(命令));
}
它表示
TopicCommand
alterTopic
方法不存在。我正在看文档,不知道如何解决它

我需要这个方法来做完全相同的事情,但是对于卡夫卡2.4版。

您应该使用来执行类似的任务

为了添加分区,这里有一个方法

例如,要将
my topic
的分区数增加到10:

Properties=newproperties();
put(“bootstrap.servers”,“localhost:9092”);
Admin=Admin.create(道具);
Map newPartitions=newhashmap();
newPartitions.put(“我的主题”,newPartitions.increaseTo(10));
CreatePartitionsResult createPartitions=admin.createPartitions(newPartitions);
createPartitions.all().get();