"Original" Kafka console consumer source code Analysis (ii)

Source: Internet
Author: User
Tags zookeeper client

We continue to discuss the implementation principle of the console Consumer, this article focuses on the use of Zookeeperconsumerconnector, that is, all subsequent content from the following statement: Val connector = consumer.create (config) So that's the problem? What does it do after this statement? Let's look at the definition of Create method def create (config:consumerconfig): Consumerconnector = {val Consumerconnect = new Zookeeperconsumercon Nector (config) Consumerconnect} shows that all of its logic is to create a Zookeeperconsumerconnector instance and invoke its constructor. Now that the problem is simple, we have to figure out what Zookeeperconsumerconnector did when he created the instance: 1. The task of creating the Kafkascheduler----The scheduler is to commit the displacements to zookeeper 2 in a timed manner. Generates the consumer.id, in the format [group.id]_ hostname-timestamp-the first 8 bits of the random uuid, or if the consumer ID is specified on the command line, the format is [Group.id]_[consumer id]3. Create the connection Zookeeper client 4. Create a CONSUMERFETCHERMANAGER5. Generate timed tasks, according to the configuration of auto.commit.interval.ms to submit the displacement, the default is 1 minutes to submit the displacement to the zookeeper is to periodically save the consumed message displacement to zookeeper, the specific logic is very simple, This article does not dwell on here. We only care about the fourth step in the previous step-creating Consumerfetchermanager. So, what does Consumerfetchermanager do with it? As the name implies, Consumerfetchermanager is the manager of a consumer fetch thread, which maintains two mappings in memory: 1. The mapping of the fetch thread to the broker, that is, what the fetch thread 2 is on each broker. Topic Partition and partition consumption information mapping, where the partition consumption information contains a lot of content, such as the bottom of the consumption queue, saved to the ZK on the consumption of displacement, the maximum displacement obtained and the size of the information. With this information, a consumer thread manager makes it easy to redistribute consumer threads dynamically.

"Original" Kafka console consumer source code Analysis (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.