/** * List the consumer groups available in the cluster with the default options. * * This is a convenience method for #{@link AdminClient#listConsumerGroups(ListConsumerGroupsOptions)} with default options. * See the overload for more details. * * @return The ListGroupsResult. */ public ListConsumerGroupsResult listConsumerGroups() { return listConsumerGroups(new ListConsumerGroupsOptions()); }
Collections.emptyList())); final ListConsumerGroupsResult result = env.adminClient().listConsumerGroups(); TestUtils.assertFutureError(result.all(), KafkaException.class);
final ListConsumerGroupsResult result = env.adminClient().listConsumerGroups(); TestUtils.assertFutureError(result.all(), UnknownServerException.class);
public synchronized List<String> listAllConsumers() { long now = System.currentTimeMillis(); if (allConsumers == null || (now - allConsumersTime) > ALL_CONSUMERS_CACHE_TIMEOUT_MS) { try { allConsumers = adminClient.listConsumerGroups() .all() .get() .stream() .map(ConsumerGroupListing::groupId) .collect(Collectors.toList()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new StreamRuntimeException(e); } catch (ExecutionException e) { throw new StreamRuntimeException(e); } if (!allConsumers.isEmpty()) { allConsumersTime = now; } } return allConsumers; }
/** * List all consumer groups on server. * @return Immutable sorted list of Consumer Group Identifiers. */ public List<ConsumerGroupIdentifier> listConsumers() { // Make request final ListConsumerGroupsResult results = adminClient.listConsumerGroups(); // Generate return list. final List<ConsumerGroupIdentifier> consumerIds = new ArrayList<>(); try { // Iterate over results results .all() .get() .forEach((result) -> { consumerIds.add( new ConsumerGroupIdentifier(result.groupId(), result.isSimpleConsumerGroup()) ); }); // Sort them by consumer Id. consumerIds.sort(Comparator.comparing(ConsumerGroupIdentifier::getId)); // return immutable list. return Collections.unmodifiableList(consumerIds); } catch (final InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Lists consumer groups. * * @param timeoutMillis The timeout to wait for. * @return A set of group IDs. * @throws ExecutionException If an unexpected error occurred. * @throws InterruptedException If the thread was interrupted. * @throws TimeoutException If a timeout occurred. */ public Set<String> listConsumerGroups(int timeoutMillis) throws ExecutionException, TimeoutException, InterruptedException { return runWithRetry(() -> { final ListConsumerGroupsResult result = admin.listConsumerGroups(new ListConsumerGroupsOptions().timeoutMs(timeoutMillis)); awaitFutures(timeoutMillis, result.all()); final Collection<ConsumerGroupListing> listings = result.all().get(); return listings.stream().map(ConsumerGroupListing::groupId).collect(Collectors.toSet()); }); }
e.printStackTrace(); Collection<ConsumerGroupListing> consumerGroups = admin.listConsumerGroups().all().get(pollingIntervalSeconds, TimeUnit.SECONDS);