parseArguments(args); adminClient = AdminClient.createSimplePlaintext(options.valueOf(bootstrapServerOption)); final String groupId = options.valueOf(applicationIdOption); if (!adminClient.describeConsumerGroup(groupId).consumers().get().isEmpty()) { throw new IllegalStateException("Consumer group '" + groupId + "' is still active. " + "Make sure to stop all running application instances before running the reset tool."); } finally { if (adminClient != null) { adminClient.close();
private AdminClient getAdminClient() { if (adminClient == null) adminClient = AdminClient.create(properties); return adminClient; }
final AdminClient adminClient = AdminClient.createSimplePlaintext(CLUSTER.bootstrapServers()); while (!adminClient.describeConsumerGroup(applicationId, 0).consumers().get().isEmpty()) { Utils.sleep(50); while (!adminClient.describeConsumerGroup(applicationId, 0).consumers().get().isEmpty()) { Utils.sleep(50);
private Set<String> listNewConsumerGroupsByTopic(@TopicExistConstraint String topic) { Set<String> result = new HashSet(); Set<String> consumersList = listAllNewConsumerGroups(); for (String c : consumersList) { AdminClient adminClient = kafkaUtils.createAdminClient(); List<AdminClient.ConsumerSummary> consumerSummaryList = CollectionConvertor.listConvertJavaList(adminClient.describeConsumerGroup(c)); Set<String> topicSet = consumerSummaryList .stream() .flatMap(cs -> CollectionConvertor.listConvertJavaList(cs.assignment()).stream()) .map(TopicPartition::topic) .filter(t -> t.equals(topic)) .distinct() .collect(toSet()); if (topicSet.size() != 0) { result.add(c); } adminClient.close(); } return result; }
public void close() { adminClient.close(); if (kafkaConsumers != null){ for (KafkaConsumer<String, Serializable> kafkaConsumer : kafkaConsumers.values()) { kafkaConsumer.close(); } } }
private Set<String> listAllNewConsumerGroups() { AdminClient adminClient = kafkaUtils.createAdminClient(); log.info("Calling the listAllConsumerGroupsFlattened"); Set activeGroups = CollectionConvertor.seqConvertJavaList(adminClient.listAllConsumerGroupsFlattened()) .stream() .map(GroupOverview::groupId) .collect(toSet()); log.info("Checking the groups in storage"); Set usedTobeGroups = storage.getMap().entrySet().stream().map(Map.Entry::getKey).collect(toSet()); activeGroups.addAll(usedTobeGroups); log.info("Finish getting new consumers"); adminClient.close(); return activeGroups; }
adminClient.listAllConsumerGroupsFlattened()); for (GroupOverview group : groups) { String groupId = group.groupId(); adminClient.describeConsumerGroup(groupId));
/** * Retrieves the {@link AdminClient.ConsumerGroupSummary} information from Kafka * * @param consumerGroup * the name of the consumer group * @return the {@link AdminClient.ConsumerGroupSummary} information from Kafka * @throws AdminOperationException * if there is an issue retrieving the consumer group summary */ public AdminClient.ConsumerGroupSummary getConsumerGroupSummary(String consumerGroup) { if (StringUtils.isBlank(consumerGroup)) throw new IllegalArgumentException("consumerGroup cannot be null, empty or blank"); try { return getAdminClient().describeConsumerGroup(consumerGroup); } catch (KafkaException e) { throw new AdminOperationException("Unable to retrieve summary for consumer group: " + consumerGroup, e); } }
List<String> groupList = JavaConversions.seqAsJavaList(adminToolsClient.listAllConsumerGroupsFlattened()) .stream().map(GroupOverview::groupId).collect(Collectors.toList()); if (shouldCollectConsumer(consumer)) { try { scala.collection.immutable.Map<TopicPartition, Object> listGroupOffsets = adminToolsClient.listGroupOffsets(consumer); java.util.Map<TopicPartition, Object> map = JavaConversions.mapAsJavaMap(listGroupOffsets); java.util.Map<String, List<Partition>> result = map.entrySet().stream().collect(
protected List<String> group() { List<String> groups = new ArrayList<>(); scala.collection.immutable.List<GroupOverview> list = adminClient.listAllConsumerGroupsFlattened(); if (list == null) return groups; Iterator<GroupOverview> iterator = list.iterator(); while (iterator.hasNext()) { groups.add(iterator.next().groupId()); } return groups; }
public AdminClient createAdminClient() { return AdminClient.createSimplePlaintext(getKafkaConfig().getBrokers()); } }
CollectionConvertor.listConvertJavaList(adminClient.describeConsumerGroup(consumerGroup)); adminClient.close();
@Override public void stop() { if (stopped.compareAndSet(false, true)) { try { metadataConsumer.close(); } catch (Exception e) { LOG.warn("metadataConsumer.close for system " + systemName + " failed with exception.", e); } } if (adminClient != null) { try { adminClient.close(); } catch (Exception e) { LOG.warn("adminClient.close for system " + systemName + " failed with exception.", e); } } }
private boolean isConsumerGroupActive(String consumerGroup, ConsumerType type) { if (type == ConsumerType.NEW) { AdminClient adminClient = kafkaUtils.createAdminClient(); boolean isActive = CollectionConvertor.seqConvertJavaList(adminClient.listAllConsumerGroupsFlattened()) .stream() .map(GroupOverview::groupId) .filter(c -> c.equals(consumerGroup)) .count() == 1; adminClient.close(); return isActive; } else if (type == ConsumerType.OLD) { return AdminUtils.isConsumerGroupActive(zookeeperUtils.getZkUtils(), consumerGroup); } else { throw new ApiException("Unknown type " + type); } }
summary = getAdminClient().describeConsumerGroup(consumerGroup); } catch (IllegalArgumentException | GroupCoordinatorNotAvailableException e) { LOG.debug("Error while attempting to describe consumer group {}", consumerGroup, e);
CollectionConvertor.listConvertJavaList(adminClient.describeConsumerGroup(consumerGroup)); adminClient.close();
public KafkaConsumerCommand(String bootstrapServer) { this.bootstrapServer = bootstrapServer; Properties props = new Properties(); props.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer); adminClient = AdminClient.create(props); }
@Override public void stop() { if (stopped.compareAndSet(false, true)) { try { metadataConsumer.close(); } catch (Exception e) { LOG.warn("metadataConsumer.close for system " + systemName + " failed with exception.", e); } } if (adminClient != null) { try { adminClient.close(); } catch (Exception e) { LOG.warn("adminClient.close for system " + systemName + " failed with exception.", e); } } }
public ConsumerGroupInfo consumerGroup(KafkaConsumer<String, Serializable> kafkaConsumer,String group){ ConsumerGroupSummary groupSummary = adminClient.describeConsumerGroup(group,30000); scala.collection.immutable.List<ConsumerSummary> consumers = groupSummary.consumers().get(); if(consumers.isEmpty()){
@Bean("adminToolsClient") public kafka.admin.AdminClient adminToolsClient(@Autowired @Qualifier("kafkaAdminProperties") Properties kafkaAdminProperties) { return kafka.admin.AdminClient.create(kafkaAdminProperties); }