kafka producer workflow

      ①, we must first construct a ProducerRecord object that can be declared topic Topic, partition Partition, keys and values ​​Key Value, themes and values ​​that must be declared, partitions and keys can not be specified.

  ②, call the send () method sends a message.

  ③, since the message is to be transmitted to the network, the effect must be serialized, serializer is the object message key and value sequence into an array of bytes.

  ④, the following data to the partition device, ProducerRecord between objects if the specified partition, then the partition will not do anything directly to the specified partition return; if not, then the partition will be selected based on a partition Key , after selecting the partition, the producers know which topics and partitions to send the records.

  ⑤, then this record is added to a record which the batch, the batch where all messages are sent to the same subject and partitions. There is a separate thread to the batch records sent to the appropriate Broker.

  ③, Broker successfully received the message indicating successful transmission, the return message metadata (including the subject and partition information and an offset recorded in the partition). Transmission failure, may choose to retry or directly thrown.

Published 107 original articles · won praise 29 · views 180 000 +

Guess you like

Origin blog.csdn.net/zhangyingchengqi/article/details/104788765