Skip to Content
Kafka权威指南
book

Kafka权威指南

by Neha Narkhede, Gwen Shapira, Todd Palino
January 2018
Beginner to intermediate
234 pages
7h 8m
Chinese
Posts & Telecom Press
Content preview from Kafka权威指南
Kafka
消费者——从
Kafka
读取数据
55
线程安全
在同一个群组里,我们无法让一个线程运行多个消费者,也无法让多个线
程安全地共享一个消费者。按照规则,一个消费者使用一个线程。如果
要在同一个消费者群组里运行多个消费者,需要让每个消费者运行在自己
的线程里。最好是把消费者的逻辑封装在自己的对象里,然后使用
Java
ExecutorService
启动多个线程,使每个消费者运行在自己的线程上。
Confluent
的博客(
https://www.confluent.io/blog/
)上有一个教程介绍如何处
理这种情况。
4.5
 消费者的配置
到目前为止,我们学习了如何使用消费者
API
,不过只介绍了几个配置属性——
bootstrap.
servers
group.id
key.deserializer
value.deserializer
Kafka
的文档列出了所有与消费者相
关的配置说明。大部分参数都有合理的默认值,一般不需要修改它们,不过有一些参数与消费
者的性能和可用性有很大关系。接下来介绍这些重要的属性。
1. fetch.min.bytes
该属性指定了消费者从服务器获取记录的最小字节数。
broker
在收到消费者的数据请求时,
如果可用的数据量小于 fetch.min.bytes 指定的大小,那么它会等到有足够的可用数据时
才把它返回给消费者。这样可以降低消费者和
broker
的工作负载,因为它们在主题不是很
活跃的时候(或者一天里的低谷时段)就不需要来来回回地处理消息。如果没有很多可用
数据,但消费者的 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通機器學習

精通機器學習

Aurélien Géron
精通特征工程

精通特征工程

Alice Zheng, Amanda Casari
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9787115473271