【kafka系列教程27】kafka分布

本文详细介绍了Kafka的消费者offset跟踪,包括如何在Kafka和Zookeeper中存储及管理offset,以及消费者如何在offset manager中进行注册和再平衡。此外,还讲述了Kafka的集群ID和broker注册,以及消费者注册算法和再平衡过程。
摘要由CSDN通过智能技术生成

消费者offset跟踪 (Consumer Offset Tracking)

The high-level consumer tracks the maximum offset it has consumed in each partition and periodically commits its offset vector so that it can resume from those offsets in the event of a restart. Kafka provides the option to store all the offsets for a given consumer group in a designated broker (for that group) called the offset manager. i.e., any consumer instance in that consumer group should send its offset commits and fetches to that offset manager (broker). The high-level consumer handles this automatically. If you use the simple consumer you will need to manage offsets manually. This is currently unsupported in the Java simple consumer which can only commit or fetch offsets in ZooKeeper. If you use the Scala simple consumer you can discover the offset manager and explicitly commit or fetch offsets to the offset manager. A consumer can look up its offset manager by issuing a ConsumerMetadataRequest to any Kafka broker and reading the ConsumerMetadataResponse which will contain the offset manager. The consumer can then proceed to commit or fetch offsets from the offsets manager broker. In case the offset manager moves, the consumer will need to rediscover the offset manager. If you wish to manage your offsets manually, you can take a look at these code samples that explain how to issue OffsetCommitRequest and OffsetFetchRequest.

高级别消费者跟踪每个分区已消费的最大的offset,并定期提交offset,在重新启动的情况下,可从这些offset恢复。Kafka提供了一个选项在指定的broker中来存储所有给定的消费者组的offset,称为offset manager。例如,该消费者组的所有消费者实例发送其offset,提交并获取该offset manager(broker)。高级别消费者都将会自动处理这些。如果你使用低级别的消费者,你将需要去手动管理offset。目前在低级别的java消费者不支持,只能在Zookeeper提交或获取offset。如果你使用简单的Scala消费者,你可拿到offset manager,并显式的提交或获取offset。消费者可以通过发送GroupCoordinatorRequest到任何的broker,并接受GroupCoordinatorResponse响应对象,对象包含offset manager,那么消费者可以继续从`offset manager broker`提交或获取offset。如果offset manager位置变动,消费者需要重新发现offset manager。如果你想手动管理你的offset,你可以看看OffsetCommitRequest 和 OffsetFetchRequest如何做的。

 

When the offset manager receives an OffsetCommitRequest, it appends the request to a special compactedKafka topic named __consumer_offsets. The offset manager sends a successful offset commit response to the consumer only after all the replicas of the offsets topic receive the offsets. In case the offsets fail to replicate within a configurable timeout, the offset commit will fail and the consumer may retry the commit after backing off. (This is done automatically by the high-level consumer.) The brokers periodically compact the offsets topic since it only needs to maintain the most recent offset commit per partition. The offset manager also caches the offsets in an in-memory table in order to serve offset fetches quickly.

当offset manager接收一个OffsetCommitRequest,它追加请求到一个特定的压缩的名为__consumer_offsets的topic中,当offset topic的所有副本接收offset之后,offset manager发送一个成功的offset提交响应给消费者。万一offset无法在规定的时间内复制,offset将提交失败,消费者在回退之后可重试该提交(高级别消费者自动做的)。broker定期压缩offset topic,只需要保存每个分区最近的offset。offset manager也缓存offset在内存表中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值