kaiffeetasse
kaiffeetasse

Reputation: 580

How to list all producers of a kafka cluster?

I am able to list all Kafka Consumer with KafkaAdminClient:

AdminClient client = AdminClient.create(conf);
ListTopicsResult ltr = client.listTopics();
KafkaFuture<Set<String>> names = ltr.names();

ArrayList<ConsumerGroupListing> consumerGroups = new ArrayList<>(client.listConsumerGroups().all().get());
ConsumerGroupListing consumerGroup = consumerGroups.get(0);

Is it possible to list all registrated producers in a similar way?

Upvotes: 12

Views: 11271

Answers (2)

senjin.hajrulahovic
senjin.hajrulahovic

Reputation: 3191

It is possible to get all active producer using AdminClient API:

Collection<TopicPartition> topicPartitions = ...

DescribeProducersResult result = adminClient.describeProducers(
  Collections.singleton(topicPartition)
);

Map<TopicPartition, DescribeProducersResult.PartitionProducerState> producerStateMap = result.all().get();

https://kafka.apache.org/32/javadoc/org/apache/kafka/clients/admin/KafkaAdminClient.html#describeProducers(java.util.Collection,org.apache.kafka.clients.admin.DescribeProducersOptions)

Upvotes: 0

Giorgos Myrianthous
Giorgos Myrianthous

Reputation: 39950

In contrast to consumers, it is not possible to retrieve such information since Kafka brokers don't store any kind of information about the producers connected to them.

Upvotes: 9

Related Questions