org.apache.kafka.clients.admin.AdminClient.deleteConsumerGroups()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中org.apache.kafka.clients.admin.AdminClient.deleteConsumerGroups()方法的一些代码示例,展示了AdminClient.deleteConsumerGroups()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AdminClient.deleteConsumerGroups()方法的具体详情如下:
包路径:org.apache.kafka.clients.admin.AdminClient
类名称:AdminClient
方法名:deleteConsumerGroups

AdminClient.deleteConsumerGroups介绍

[英]Delete consumer groups from the cluster with the default options.
[中]使用默认选项从群集中删除消费者组。

代码示例

代码示例来源:origin: apache/kafka

/**
 * Delete consumer groups from the cluster with the default options.
 *
 * @return The DeleteConsumerGroupResult.
 */
public DeleteConsumerGroupsResult deleteConsumerGroups(Collection<String> groupIds) {
  return deleteConsumerGroups(groupIds, new DeleteConsumerGroupsOptions());
}

代码示例来源:origin: apache/kafka

@Test
public void testDeleteConsumerGroups() throws Exception {
  final HashMap<Integer, Node> nodes = new HashMap<>();
  nodes.put(0, new Node(0, "localhost", 8121));
  final Cluster cluster =
    new Cluster(
      "mockClusterId",
      nodes.values(),
      Collections.<PartitionInfo>emptyList(),
      Collections.<String>emptySet(),
      Collections.<String>emptySet(), nodes.get(0));
  final List<String> groupIds = singletonList("group-0");
  try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(cluster)) {
    env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
    //Retriable FindCoordinatorResponse errors should be retried
    env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.COORDINATOR_NOT_AVAILABLE,  Node.noNode()));
    env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.COORDINATOR_LOAD_IN_PROGRESS, Node.noNode()));
    env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
    final Map<String, Errors> response = new HashMap<>();
    response.put("group-0", Errors.NONE);
    env.kafkaClient().prepareResponse(new DeleteGroupsResponse(response));
    final DeleteConsumerGroupsResult result = env.adminClient().deleteConsumerGroups(groupIds);
    final KafkaFuture<Void> results = result.deletedGroups().get("group-0");
    assertNull(results.get());
    //should throw error for non-retriable errors
    env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.GROUP_AUTHORIZATION_FAILED,  Node.noNode()));
    final DeleteConsumerGroupsResult errorResult = env.adminClient().deleteConsumerGroups(groupIds);
    TestUtils.assertFutureError(errorResult.deletedGroups().get("group-0"), GroupAuthorizationException.class);
  }
}

代码示例来源:origin: SourceLabOrg/kafka-webview

/**
 * Removes a consumer's state.
 * @param id id of consumer group to remove.
 * @return boolean true if success.
 * @throws RuntimeException on underlying errors.
 */
public boolean removeConsumerGroup(final String id) {
  final DeleteConsumerGroupsResult request = adminClient.deleteConsumerGroups(Collections.singleton(id));
  try {
    request.all().get();
    return true;
  } catch (InterruptedException | ExecutionException e) {
    // TODO Handle this
    throw new RuntimeException(e.getMessage(), e);
  }
}

代码示例来源:origin: com.obsidiandynamics.jackdaw/jackdaw-core

final DeleteConsumerGroupsResult result = admin.deleteConsumerGroups(groups, 
                                   new DeleteConsumerGroupsOptions().timeoutMs(timeoutMillis));
awaitFutures(timeoutMillis, result.deletedGroups().values());

相关文章