You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Joe San <co...@gmail.com> on 2016/02/10 09:39:34 UTC

Kafka 0.8.2 Consumer

In the following bit of code that I got from

https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+SimpleConsumer+Example

/**
 * gives us the leader partition metadata for the given
 * host and port! there can be only one broker that is
 * the leader for the given partitionId
 */
val partitionMetaDataSeq = for {
  mataData  <- topicMetadataResponse
  partition <- mataData.partitionsMetadata.asScala.toSeq
  if partition.partitionId == partitionId
} yield partition

is my understanding correct, which is:

the topicMetadataResponse that I get is a sequence of TopicMetadata which
in turn contains a sequence of PartitionMetadata. But how could I get a
sequence of TopicMetadata when I do a look up only for a single topic?

val topicMetadataRequest = new TopicMetadataRequest(topics.asJava)
val topicMetadataResponse =
  simpleConsumer.send(topicMetadataRequest).topicsMetadata.asScala.toSeq


The topics.asJava contains only a single topic!