kafka consumer partition分配

成功Rebalance的结果是,被订阅的所有Topic的每一个Partition将会被Consumer Group内的一个(有且仅有一个)Consumer拥有。每一个Broker将被选举为某些Consumer Group的Coordinator。某个Cosnumer Group的Coordinator负责在该Consumer Group的成员变化或者所订阅的Topic的Partititon变化时协调Rebalance操作。

  • ConsumerCoordinator

coordinator协议,自动分配partition

ConsumerCoordinator构造函数:

    public ConsumerCoordinator(LogContext logContext,
                               ConsumerNetworkClient client,
                               String groupId,
                               int rebalanceTimeoutMs,
                               int sessionTimeoutMs,
                               int heartbeatIntervalMs,
                               List<PartitionAssignor> assignors,
                               Metadata metadata,
                               SubscriptionState subscriptions,
                               Metrics metrics,
                               String metricGrpPrefix,
                               Time time,
                               long retryBackoffMs,
                               boolean autoCommitEnabled,
                               int autoCommitIntervalMs,
                               ConsumerInterceptors<?, ?> interceptors,
                               boolean excludeInternalTopics,
                               final boolean leaveGroupOnClose) 

其中metedata会更新broker的address,即ip和端口

metadata.update(Cluster.bootstrap(addresses), Collections.<String>emptySet(), 0);
  • SubscriptionState

这个部件维护了Consumer的消费状态

  • 参考:

Kafka中的coordinator

Kafka源码深度解析-序列9 -Consumer -SubscriptionState内部结构分析

Kafka设计解析(八)- Exactly Once语义与事务机制原理

猜你喜欢

转载自blog.csdn.net/zilong230905/article/details/83186504