consumer.How to specify partition to read? [kafka]

后端 未结 1 1030
醉酒成梦
醉酒成梦 2021-01-04 04:41

I am introducing with kafka and I want to know how to specify partition when I consume messages from topic.

I have found several picture like this:

相关标签:
1条回答
  • 2021-01-04 05:16

    There are two ways to tell what topic/partitions you want to consume: KafkaConsumer#assign() (you specify the partition you want and the offset where you begin) and subscribe (you join a consumer group, and partition/offset will be dynamically assigned by group coordinator depending of consumers in the same consumer group, and may change during runtime)

    In both case, you need to poll to receive data.

    See https://kafka.apache.org/0110/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html, especially paragraphs Consumer Groups and Topic Subscriptions and Manual Partition Assignment

    0 讨论(0)
提交回复
热议问题