简体   繁体   English

如何从Java代码中删除Kafka主题的使用者组?

[英]How to delete a consumer group of a Kafka Topic from java code?

I have a kafka topic T. 我有一个卡夫卡主题T。

The user has the option to create new entries A, B, C or delete them. 用户可以选择创建新条目A,B,C或删除它们。 Upon creation of each of the entries A,B or C; 创建每个条目A,B或C时; I will create a consumer group with the same name for the kafka topic T. 我将为kafka主题T创建一个具有相同名称的消费者组。

Upon deleting the entries A,B,C; 在删除条目A,B,C时; I want to delete the corresponding consumer groups without affecting the topic T by any way - but I want to achieve this from a Java module. 我想删除相应的使用者组而不会以任何方式影响主题T-但我想从Java模块中实现这一点。 How is that possible? 那怎么可能?

Currently, there is only limited Java API for this. 当前,仅有有限的Java API用于此目的。 There is a discussion in progress to add a Java AdminClient (cf. https://cwiki.apache.org/confluence/display/KAFKA/KIP-117%3A+Add+a+public+AdminClient+API+for+Kafka+admin+operations ) 正在进行有关添加Java AdminClient的讨论(请参阅https://cwiki.apache.org/confluence/display/KAFKA/KIP-117%3A+Add+a+public+AdminClient+API+for+Kafka+管理员+操作

For Zookeeper based consumer groups (ie, old consumer from v0.8) you can have a look into the code of ConsumerGroupCommand -- that's Scala code, but you can still call it from Java. 对于基于Zookeeper的使用者组(即v0.8中的旧使用者),您可以查看ConsumerGroupCommand的代码-这是Scala代码,但是您仍然可以从Java调用它。

For broker based consumer groups (ie, new consumer as of v0.9) you cannot delete a consumer group at all (at the moment -- it's WIP to add support for this). 对于基于经纪人的消费者组(即v0.9以后的新消费者),您根本无法删除一个消费者组(此刻,WIP为此添加了支持)。 However, brokers delete consumer groups automatically if they are not active anymore. 但是,如果经纪人不再处于活动状态,则经纪人会自动删除它们。 You can configure this "delay" via broker setting offsets.retention.minutes (a group is deleted if all of its committed offsets got deleted). 您可以通过代理设置offsets.retention.minutes来配置此“延迟”(如果删除了所有已提交的偏移量,则该组将被删除)。

I don't have enough points to comment but if your just looking to delete a consumer group the only way to do it is to delete the zookeeper entry /consumers/[group_id] . 我没有足够的意见要发表,但是如果您只是想删除某个消费者组,那么唯一的方法就是删除zookeeper条目/consumers/[group_id] Here's a link that should point you in the right direction: removing a kafka consumer group in zookeeper 这里的链接应该为您指明正确的方向: 在Zookeeper中删除kafka消费者组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM