kafka--- consumer 消费消息
1、 consumer API kafka 提供了两套 consumer API: 1. The high-level Consumer API 2. The SimpleConsumer API 其中 high-level consumer API 提供了一个从 kafka 消费数据的高层抽象,而 SimpleConsumer API 则需要开发人员更多地关注细节。 1.1 The high-level consumer API high-level consumer API 提供了 consumer group 的语义,一个消息只能被 group 内的一个 consumer 所消费,且 consumer 消费消息时不关注 offset,最后一个 offset 由 zookeeper 保存。 使用 high-level consumer API 可以是多线程的应用,应当注意: 1. 如果消费线程大于 patition 数量,则有些线程将收不到消息 2. 如果 patition 数量大于线程数,则有些线程多收到多个 patition 的消息 3. 如果一个线程消费多个 patition,则无法保证你收到的消息的顺序,而一个 patition 内的消息是有序的 1.2 The SimpleConsumer API 如果你想要对 patition 有更多的控制权,那就应该使用