简体   繁体   English

不同 Kafka 主题上的分区是否位于同一消费者(k8s pod)中

[英]Are partitions on different Kafka topics co-located within same consumer (k8s pod)

I have a requirement where I want to be able to read data from partition 1 of topic A and partition 1 of topic B from the same consumer, I have a group of consumers running in different Kubernetes pods.我有一个要求,我希望能够从同一消费者的主题 A 的分区 1 和主题 B 的分区 1 读取数据,我有一组消费者在不同的 Kubernetes pod 中运行。 Both topics will have 5 partitions each and both topics have key based partition strategy.两个主题都有 5 个分区,并且两个主题都有基于键的分区策略。 So assuming partition 1 on topic A and partition 1 on topic B are keyed with same key value would they both colocate on the same consumer or pod.因此,假设主题 A 上的分区 1 和主题 B 上的分区 1 使用相同的键值进行键控,它们是否都位于同一个使用者或 pod 上。 If that's the case then I can cross reference data from one topic using the key of the other topic's message.如果是这种情况,那么我可以使用另一个主题消息的键来交叉引用来自一个主题的数据。

Thank you谢谢

There is no guarantee that a consumer will be assigned the same partitions across two topics.不能保证会为消费者分配跨两个主题的相同分区。 Keys are only relevant to the producer partitioner.密钥仅与生产者分区器相关。

If you must consume the same partition of multiple topics, you may assign() those values to the consumer instance rather than subscribe() -ing to the whole topic.如果您必须使用多个主题的同一分区,则可以将这些值assign()给消费者实例,而不是subscribe()给整个主题。

However, if you are wanting to join data across topics, the more appropriate way to do this would be to use Kafka Streams / KSQL joins.但是,如果您想要跨主题连接数据,更合适的方法是使用 Kafka Streams / KSQL 连接。

Yes, if you configure routing by key for both topics, same key will be sent to same partition.是的,如果您为两个主题配置了按键路由,相同的密钥将被发送到同一个分区。 Have a look at the documentation here: https://kafka.apache.org/documentation/#design_loadbalancing在此处查看文档: https://kafka.apache.org/documentation/#design_loadbalancing

"For example if the key chosen was a user id then all data for a given user would be sent to the same partition. This in turn will allow consumers to make locality assumptions about their consumption. This style of partitioning is explicitly designed to allow locality-sensitive processing in consumers." “例如,如果选择的键是用户 ID,那么给定用户的所有数据都将被发送到同一个分区。这反过来将允许消费者对其消费做出局部性假设。这种分区风格明确设计为允许局部性- 消费者的敏感处理。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM