Understanding Kafka Topics and Partitions

后端 未结 3 879
时光说笑
时光说笑 2020-12-04 04:30

I am starting to learn Kafka for enterprise solution purposes.

During my readings, some questions came to my mind:

  1. When a producer is producing a messa
3条回答
  •  情深已故
    2020-12-04 05:01

    Let's take those in order :)

    1 - When a producer is producing a message - It will specify the topic it wants to send the message to, is that right? Does it care about partitions?

    By default, the producer doesn't care about partitioning. You have the option to use a customized partitioner to have a better control, but it's totally optional.


    2 - When a subscriber is running - Does it specify its group id so that it can be part of a cluster of consumers of the same topic or several topics that this group of consumers is interested in?

    Yes, consumers join (or create if they're alone) a consumer group to share load. No two consumers in the same group will ever receive the same message.


    3 - Does each consumer group have a corresponding partition on the broker or does each consumer have one?

    Neither. All consumers in a consumer group are assigned a set of partitions, under two conditions : no two consumers in the same group have any partition in common - and the consumer group as a whole is assigned every existing partition.


    4 - Are the partitions created by the broker, therefore not a concern for the consumers?

    They're not, but you can see from 3 that it's totally useless to have more consumers than existing partitions, so it's your maximum parallelism level for consuming.


    5 - Since this is a queue with an offset for each partition, is it responsibility of the consumer to specify which messages it wants to read? Does it need to save its state?

    Yes, consumers save an offset per topic per partition. This is totally handled by Kafka, no worries about it.


    6 - What happens when a message is deleted from the queue? - For example: The retention was for 3 hours, then the time passes, how is the offset being handled on both sides?

    If a consumer ever request an offset not available for a partition on the brokers (for example, due to deletion), it enters an error mode, and ultimately reset itself for this partition to either the most recent or the oldest message available (depending on the auto.offset.reset configuration value), and continue working.

提交回复
热议问题