Hi Anand,

AdminClient is more recommended to get 
cluster/broker/topic/partition/replication metadata and these apis are under 
evolving , KafkaProducer is mostly used to produce record and less used to 
query metadata information.

Ziming

> On Jun 10, 2025, at 10:33 PM, Subra I <iamsubra...@gmail.com> wrote:
> 
> Hi All,
> 
> I need to know the number of partitions for a topic before
> producing/consuming. Some users may set the number of partitions for a
> given topic but some users may just set the number of partitions in
> server.properties. It should work for both cases.
> 
> Which method is better for a production grade software:
> 
> 1. KafkaProducer partitionsFor
> 2. KafkaAdminClient describeTopics: you need to extract the topic you are
> interested in and get the partition info from the metadata.
> 
> A quick Google search tells me that describeTopics approach is more
> comprehensive.
> 
> Also, will the use of KafkaProducer partitionsFor work for clustered
> environments?
> 
> Thanks,
> Anand

Reply via email to