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
153
9.5
 消费和生产
在使用
Kafka
时,有时候为了验证应用程序,需要手动读取消息或手动生成消息。这个时
候可以借助
kafka-console-consumer.sh
kafka-console-producer.sh
这两个工具,它们包装
Java
客户端,让用户不需要编写整个应用程序就可以与
Kafka
主题发生交互。
将结果输出到其他应用程序
有时候,我们可能需要编写应用程序将控制台消费者和控制台生产者包装起
来,用它读取消息,并把消息传给另一个应用程序去处理。这种应用程序太
过脆弱,应该尽量避免编写这类应用程序。我们无法保证控制台消费者不丢
失数据,也无法使用控制台生产者的所有特性,而且它发送数据的方式也很
奇怪。最好的方式是直接使用
Java
客户端,或者使用其他基于
Kafka
协议实
现的第三方客户端(可能是使用其他语言开发的)。
9.5.1
 控制台消费者
kafka-console-consumer.sh
工具提供了一种从一个或多个主题上读取消息的方式。消息被打
印在标准输出上,消息之间以空行分隔。默认情况下,它会打印没有经过格式化的原始消
息字节(使用 DefaultFormatter)。它有很多可选参数,其中有一些基本的参数是必选的。
检查工具版本
使用与
Kafka broker
相同版本的消费者客户端,这一点是非常重要的。旧版
本的控制台消费者与
Zookeeper
之间不恰当的交互行为可能会影响到集群。
第一步要指定是否使用新版本的消费者,并指定
Kafka
集群的地址。如果使用的是旧版本的 ...
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