Kafka提供了两种Consumer API
- High Level Consumer API
- Low Level Consumer API(Kafka诡异的称之为Simple Consumer API,实际上非常复杂)
1. High Level Consumer API概述
High Level Consumer API围绕着Consumer Group这个逻辑概念展开,它屏蔽了每个Topic的每个Partition的Offset管理(自动读取zookeeper中该Consumer group的last offset )、Broker失败转移以及增减Partition、Consumer时的负载均衡(当Partition和Consumer增减时,Kafka自动进行负载均衡)
2. Low Level Consumer API概述
功能更强大,复杂度高,负载均衡等都要自己实现。
- Read a message multiple times(重复读取)
- Consume only a subset of the partitions in a topic in a process(跳读)
- Manage transactions to make sure a message is processed once and only once(Exactly Once原语)