Search in sources :

Example 6 with DescribeTopicsResult

use of org.apache.kafka.clients.admin.DescribeTopicsResult in project core-ng-project by neowu.

the class KafkaController method topics.

public Response topics(Request request) throws ExecutionException, InterruptedException {
    ControllerHelper.assertFromLocalNetwork(request.clientIP());
    List<KafkaTopic> views = Lists.newArrayList();
    try (AdminClient admin = kafka.admin()) {
        Set<String> topics = admin.listTopics().names().get();
        DescribeTopicsResult descriptions = admin.describeTopics(topics);
        for (Map.Entry<String, KafkaFuture<TopicDescription>> entry : descriptions.values().entrySet()) {
            String name = entry.getKey();
            TopicDescription description = entry.getValue().get();
            KafkaTopic view = view(name, description);
            views.add(view);
        }
    }
    return Response.bean(views);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) Map(java.util.Map) AdminClient(org.apache.kafka.clients.admin.AdminClient)

Example 7 with DescribeTopicsResult

use of org.apache.kafka.clients.admin.DescribeTopicsResult in project eventapis by kloiasoft.

the class ListTopicSchedule method runInternal.

@Override
boolean runInternal(StopWatch stopWatch) throws InterruptedException, ExecutionException {
    stopWatch.start("adminClient.listTopics()");
    Collection<String> topicNames = adminClient.listTopics().listings().get().stream().map(TopicListing::name).filter(this::shouldCollectEvent).collect(Collectors.toList());
    topicsMap.removeAll(new RemoveTopicPredicate(topicNames));
    DescribeTopicsResult describeTopicsResult = adminClient.describeTopics(topicNames);
    describeTopicsResult.all().get().forEach((topic, topicDescription) -> topicsMap.executeOnKey(topic, new SetTopicPartitionsProcessor(topicDescription.partitions().stream().map(TopicPartitionInfo::partition).collect(Collectors.toList()))));
    metaMap.set(this.getName() + TopicServiceScheduler.LAST_SUCCESS_PREFIX, System.currentTimeMillis());
    log.debug("Topics:" + topicsMap.entrySet());
    log.debug(stopWatch.prettyPrint());
    return true;
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicListing(org.apache.kafka.clients.admin.TopicListing) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult)

Aggregations

DescribeTopicsResult (org.apache.kafka.clients.admin.DescribeTopicsResult)7 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AdminClient (org.apache.kafka.clients.admin.AdminClient)2 KafkaFuture (org.apache.kafka.common.KafkaFuture)2 TopicPartitionInfo (org.apache.kafka.common.TopicPartitionInfo)2 ExecutionException (java.util.concurrent.ExecutionException)1 DescribeTopicsOptions (org.apache.kafka.clients.admin.DescribeTopicsOptions)1 TopicListing (org.apache.kafka.clients.admin.TopicListing)1 SaslAuthenticationException (org.apache.kafka.common.errors.SaslAuthenticationException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)1 Test (org.junit.Test)1