} finally { if (adminClient != null) { adminClient.close();
public void close() { adminClient.close(); if (kafkaConsumers != null){ for (KafkaConsumer<String, Serializable> kafkaConsumer : kafkaConsumers.values()) { kafkaConsumer.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); } } }
@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 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; }
@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 (adminClientForDelete != null) { try { adminClientForDelete.close(); } catch (Exception e) { LOG.warn("AdminClient.close() for system {} failed with exception {}.", systemName, e); } } if (adminClient != null) { adminClient.close(); } }
@Override public void close() { zkUtils.close(); if (authorizer != null) authorizer.close(); if (adminClient != null) adminClient.close(); }
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; }
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); } }
CollectionConvertor.listConvertJavaList(adminClient.describeConsumerGroup(consumerGroup)); adminClient.close();
CollectionConvertor.listConvertJavaList(adminClient.describeConsumerGroup(consumerGroup)); adminClient.close();