码迷,mamicode.com
首页 > 其他好文 > 详细

Kafka note

时间:2019-10-31 01:04:43      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:sign   uil   nts   meta   The   fun   record   sub   beyond   

  • The Kafka cluster stores streams of records in categories called topics.
  • Each record consists of a key, a value, and a timestamp.
  • Kafka has four core APIs: Producer(publish a stream of records to one or more Kafka topics), Consumer(subscribe to one or more topics and process the stream of records produced to them), Streams(act as a stream processor, consuming an input stream from one or more topics and producing an output stream to one or more output topics, effectively transforming the input streams to output streams), Connector(allows building and running reusable producers or consumers that connect Kafka topics to existing applications or data systems)
  • In Kafka the communication between the clients and the servers is done with TCP
  • A topic is a category or feed name to which records are published, a topic can have zero, one, or many consumers that subscribe to the data written to it.
  • For each topic, the Kafka cluster maintains a partitioned log, like this
                        Anatomy of Topic
partiotion 0: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
partiotion 1: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ...
partiotion 2: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | ...
..........................................................
Old ------------------------------>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> New
  • Each partition is an ordered, immutable sequence of records that is continually appended to—a structured commit log. The records in the partitions are each assigned a sequential id number called the offset that uniquely identifies each record within the partition.
  • The Kafka cluster durably persists all published records—whether or not they have been consumed—using a configurable retention period, after which it will be discarded to free up space.
  • The only metadata retained on a per-consumer basis is the position of that consumer in the log.
  • This offset is controlled by the consume, so that the consumer can consume records in any order it likes, normally is linearly.
  • Kafka consumers are very cheap, for example, you can use our command line tools to "tail" the contents of any topic without changing what is consumed by any existing consumers.
  • The partitions in the log serve several purposes. First, they allow the log to scale beyond a size that will fit on a single server, a topic may have many partitions so it can handle an arbitrary amount of data. Second they act as the unit of parallelism—more on that in a bit.
  • The partitions of the log are distributed over the servers in the Kafka cluster with each server handling data and requests for a share of the partitions, each partition is replicated across a configurable number of servers for fault tolerance.
  • Each partition has one server which acts as the "leader" and zero or more servers which act as "followers". The leader handles all read and write requests for the partition while the followers passively replicate the leader. If the leader fails, one of the followers will automatically become the new leader. Each server acts as a leader for some of its partitions and a follower for others so load is well balanced within the cluster.
  • The producer is responsible for choosing which record to assign to which partition within the topic. This can be done in a round-robin fashion simply to balance load or it can be done according to some semantic partition function (say based on some key in the record).

Kafka note

标签:sign   uil   nts   meta   The   fun   record   sub   beyond   

原文地址:https://www.cnblogs.com/seliote/p/11768839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!