Search in sources :

Example 1 with DescribeConsumerGroupsOptions

use of org.apache.kafka.clients.admin.DescribeConsumerGroupsOptions in project kafka by apache.

the class StreamsResetter method maybeDeleteActiveConsumers.

private void maybeDeleteActiveConsumers(final String groupId, final Admin adminClient) throws ExecutionException, InterruptedException {
    final DescribeConsumerGroupsResult describeResult = adminClient.describeConsumerGroups(Collections.singleton(groupId), new DescribeConsumerGroupsOptions().timeoutMs(10 * 1000));
    final List<MemberDescription> members = new ArrayList<>(describeResult.describedGroups().get(groupId).get().members());
    if (!members.isEmpty()) {
        if (options.has(forceOption)) {
            System.out.println("Force deleting all active members in the group: " + groupId);
            adminClient.removeMembersFromConsumerGroup(groupId, new RemoveMembersFromConsumerGroupOptions()).all().get();
        } else {
            throw new IllegalStateException("Consumer group '" + groupId + "' is still active " + "and has following members: " + members + ". " + "Make sure to stop all running application instances before running the reset tool." + " You can use option '--force' to remove active members from the group.");
        }
    }
}
Also used : RemoveMembersFromConsumerGroupOptions(org.apache.kafka.clients.admin.RemoveMembersFromConsumerGroupOptions) MemberDescription(org.apache.kafka.clients.admin.MemberDescription) ArrayList(java.util.ArrayList) DescribeConsumerGroupsResult(org.apache.kafka.clients.admin.DescribeConsumerGroupsResult) DescribeConsumerGroupsOptions(org.apache.kafka.clients.admin.DescribeConsumerGroupsOptions)

Aggregations

ArrayList (java.util.ArrayList)1 DescribeConsumerGroupsOptions (org.apache.kafka.clients.admin.DescribeConsumerGroupsOptions)1 DescribeConsumerGroupsResult (org.apache.kafka.clients.admin.DescribeConsumerGroupsResult)1 MemberDescription (org.apache.kafka.clients.admin.MemberDescription)1 RemoveMembersFromConsumerGroupOptions (org.apache.kafka.clients.admin.RemoveMembersFromConsumerGroupOptions)1