Topics, partitions and keys

前端 未结 2 1723
梦毁少年i
梦毁少年i 2021-01-30 07:09

I am looking for some clarification on the subject. In Kafka documentations I found the following:

Kafka only provides a total order over messages within a partition, no

2条回答
  •  长发绾君心
    2021-01-30 07:39

    Igor,

    Partitions increase parallelism of Kafka topic. Any number of consumers/producers can use the same partition. Its up to application layer to define the protocol. Kafka guarantees delivery. Regarding the API, you may want to look at Java docs as they may be more complete. Based on my experience:

    1. Partitions start from 0
    2. Keys may be used to send messages to the same partition. For example hash(key)%num_partition. The logic is pluggable to Producer. https://kafka.apache.org/090/javadoc/index.html?org/apache/kafka/clients/producer/Partitioner.html
    3. Yes. but be careful not to end up with some key that will result in the "dedicated" partition. For this, you may want to have dedicated topic. For example, control topic and data topic
    4. This seems to be the same question as 3.
    5. I believe consumers should not make assumptions of the data based on partition. The typical approach is to have consumer group that can read from multiple partitions of a topic. If you want to have dedicated channels, it is better (safer/maintainable) to use separate topics.

提交回复
热议问题