consumer group search and delete function

This commit is contained in:
许晓东
2021-09-11 16:19:13 +08:00
parent d36791e600
commit 968d053bcd
8 changed files with 101 additions and 43 deletions

View File

@@ -4,7 +4,7 @@ import java.util
import java.util.{Collections, Set}
import com.xuxd.kafka.console.config.KafkaConfig
import org.apache.kafka.clients.admin.{ConsumerGroupDescription, ListConsumerGroupsOptions}
import org.apache.kafka.clients.admin.{ConsumerGroupDescription, DeleteConsumerGroupsOptions, ListConsumerGroupsOptions}
import org.apache.kafka.common.ConsumerGroupState
import scala.jdk.CollectionConverters.{CollectionHasAsScala, SetHasAsJava}
@@ -35,4 +35,19 @@ class ConsumerConsole(config: KafkaConfig) extends KafkaConsole(config: KafkaCon
Collections.emptySet()
}).asInstanceOf[Set[ConsumerGroupDescription]]
}
def deleteConsumerGroups(groupIds: util.Collection[String]): (Boolean, String) = {
if (groupIds == null || groupIds.isEmpty) {
(false, "group id is empty.")
} else {
withAdminClientAndCatchError(admin => {
admin.deleteConsumerGroups(groupIds, new DeleteConsumerGroupsOptions).all().get()
(true, "")
}
, e => {
log.error("deleteConsumerGroups error.", e)
(false, e.getMessage)
}).asInstanceOf[(Boolean, String)]
}
}
}