简体   繁体   English

Kafka分区再平衡spring for kafka

[英]Kafka partition rebalancing in spring for kafka

I have a micro-service which is using spring for Kafka consumer using @KafkaListener with some group id.我有一个微服务,它使用带有一些组 ID 的 @KafkaListener 为 Kafka 消费者使用@KafkaListener This application is deployed to the cloud with two instances in different regions.此应用程序部署到云中,具有不同区域的两个实例。

So now i think the partition is divided among two consumers as they both have same group id.所以现在我认为分区在两个消费者之间划分,因为他们都有相同的组 ID。

Is there any possible way to assign all the partitions to a single instance.有没有可能将所有分区分配给单个实例的方法。 I don't want partition rebalance.我不想要分区重新平衡。

How to create customised offset using ConsumerRebalanceListener in spring kafka application?如何在 spring kafka 应用程序中使用 ConsumerRebalanceListener 创建自定义偏移量?

You should be able to set partition.assignment.strategy property of the consumer to org.apache.kafka.clients.consumer.StickyAssignor您应该能够将消费者的partition.assignment.strategy属性设置为org.apache.kafka.clients.consumer.StickyAssignor

It's stated goal is它的既定目标是

Guarantees an assignment that is maximally balanced while preserving as many existing partition assignments as possible.保证分配是最大平衡的,同时保留尽可能多的现有分区分配。

I've personally not used it, but if I understand it's purpose correctly, if you start another consumer in the same group, there would not be rebalancing until that first consumer dies.我个人没有使用过它,但如果我正确理解它的目的,如果您在同一组中启动另一个消费者,那么在第一个消费者死亡之前不会再平衡。

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

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