kafka transmission data, explain how to determine the source partition

Each record has a key

Its role is to

  1 as a metadata record

  2 for partition, in order to determine which record to enter, then the specific code is how to achieve it? We view the source code

partition
    if all of the message is the same key, will be placed in the same partition
Kafka send a message flow
    1 determined there is no interceptor, the interceptor will be executed if the send interceptor

    2 got Cluster
    . 3 sequence of key and value pair of
    4 calculates which this message is sent to the partition

 partition calculation as follows:

  Step Two: Find the default class that implements this interface, we go in and see the point

 The third step: we see the implementation class

After understanding the source of our own to achieve a partition

Let's test launch two kafka in the unit, and then transmits data, test data on which partition

  The first step : We did not use the spring, then the frame is not our custom partition will be informed kafka, how do we write the partition plus his own into it? Let's look at the source code

  Guess configuration information should kafka configuration class, we find the information ProducerConfig class at the beginning of the search partition

Step Two : Create topic

Step Three: Write Sender

 

 

Step Four : Test

 When we put the key to LOGOFF when the console is printed as follows

When we set the LOGIN key when the console is printed as follows

When we set up an illegal key time

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

--- end --- restore content

Guess you like

Origin www.cnblogs.com/wangpipi/p/11103951.html