Kafka 0.10.0文档翻译一

1.kafka核心API

Kafka has four core APIs:

kafk有四个核心API:

The Producer API allows an application to publish a stream records to one or more Kafka topics.

Producer接口允许应用发送流数据到一个或多个topics

The Consumer API allows an application to subscribe to one or more topics and process the stream of records produced to them.

Consumer接口允许应用订阅一个或多个topics并处理为其生成的数据记录流

The Streams API allows an application to 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.

Streams接口允许应用作为流处理器,从一个或多个topics中消费输入流,并将输出流输出到一个或多个topics,实际就是将input stream转化成output stream

The Connector API allows building and running reusable producers or consumers that connect Kafka topics to existing applications or data systems.For example, a connector to a relational database might capture every change to

Connector API允许已有应用或数据系统 构建并运行 可重用的连接到Kafka topics的生产者或消费者。例如,对于一个关系数据库的connector可能获取所有的变化数据

2. 通信协议

In Kafka the communication between the clients and the servers is done with a simple, high-performance, language agnostic TCP protocol. This protocol is versioned and maintains backwards compatibility with older version. We provide a Java client for Kafka, but clients are available in many languages.

Kafka客户端与服务端通信使用简单的、高性能的,与语言无关的TCP协议。此协议版本向后兼容旧版本协议。我们提供了kafka的JAVA客户端,但其它语言客户端也可用

Topics有一个可配置的保留时间策略
消费者要保留的元数据为偏移量,可以从任意位置开始消费
对于第一个topic, kafka维护一个日志
日志中的分区有几种功能:

1.它允许日志扩展超出单服务器能力
--每个分区不能超过单服务器能力,但一个topic可以有多个分区,可任意大小
2.它们可以并行处理

3. 特性

3.1分布式

日志的分布在集群,每个服务器作为分区的一部分来处理数据及请求
各分区通过可配置数量的副本服务器以容错

每个分区有一个主,同时有0个或多个从,主服务器处理所有的请求,从服务器被动服务主服务器,如果主服务器失败了,从之一将自动变为主;集群中每个服务器作为部分分区的主,同时作为部分分区的从

3.2生产者

生产者发布数据到选择的topic,生产者负责选择当前记录发布到哪个分区,可以以简单循环的方式进行负载均衡,也可以使用某些分区函数进行分区

3.3消费者

消费者有一个group标签,每个record只会分发给同group中的任意一个消费者,消费者可以在不同的机器或不同的进程

这边相当于activeMq中虚拟主题的订阅

Per-partition ordering combined with the ability to partition data by key is sufficient for most applications.

kafka只提供了分区完整顺序,而非整个topic中的所有分区

Per-partition ordering combined with the ability to partition data by key is sufficient for most applications.

分区内的顺序性与数据按key分区的能力结合足以满足大多数应用需求

However, if you require a total order over records this can be achieved with a topic that has only one partition, though this will mean only one consumer process per consumer group.

但是,如果你需要完整记录的顺序,只能通过只有一个分区的topic来实现,然而这意味着每组消费者中只能单一消费者处理数据[分区后可以多个消费者处理]

3.4约定

Kafka在高层次提供以下保证:

  • 日志中记录的顺序按照生产者发送到特定topic分区中的顺序
  • 消费者实例看到记录按照日志中顺序
  • 对于一个复制因子为N的topic,在保证不丢失数据的情况下,最大容忍N-1的服务器失败

Note however that there cannot be more consumer instances in a consumer group than partitions.

4. 使用

4.1作为消息系统

发布订阅

4.2作为存储系统

可以作为分布式存储系统

4.3流处理

It isn't enough to just read, write, and store streams of data, the purpose is to enable real-time processing of streams.

仅读写及保存流数据是不够的,kafka目标是能够实时处理流数据

In Kafka a stream processor is anything that takes continual streams of data from input topics, performs some processing on this input, and produces continual streams of data to output topics.

Kafka中一个流处理器从输入topic中持续地取数据流,执行一些处理,并持续输出数据流到输入topic中。

This allows building applications that do non-trivial processing that compute aggregations off of streams or join streams together.

将允许构建应用做特别的操作来做流的做流的计算聚合或合并流

This facility helps solve the hard problems this type of application faces: handling out-of-order data, reprocessing input as code changes, performing stateful computations, etc.

这些设施帮助解决应用面对的一些复杂问题:处理无序数据,代码更改时重新处理输入,处理状态性的计算等

The streams API builds on the core primitives Kafka provides: it uses the producer and consumer APIs for input, uses Kafka for stateful storage, and uses the same group mechanism for fault tolerance among the stream processor instances.

关于streams的API基于Kafka提供的核心原语:使用Producer和Consumer的API进行输入,使用Kafka有状态存储,并使用分组机制以进行流处理容错。

5.总结

This combination of messaging, storage, and stream processing may seem unusual but it is essential to Kafka's role as a streaming platform.

消息,存储及流处理的结合看来起好像不常见,但对于作为流处理平台的kafka是完全必须的

A distributed file system like HDFS allows storing static files for batch processing. Effectively a system like this allows storing and processing historical data from the past.

像HDFS这样的分布式文件系统允许批量存储静态文件。实际上看这样的系统允许存储和处理过去的历史数据

A traditional enterprise messaging system allows processing future messages that will arrive after you subscribe. Applications built in this way process future data as it arrives.

传统的企业消息系统允许处理在你订阅时间点之后的消息。应用在这种方式下构建用来处理即将到达的消息

Kafka combines both of these capabilities, and the combination is critical both for Kafka usage as a platform for streaming applications as well as for streaming data pipelines.

kafka融合了以上三种能力,这种融合对于作为流处理应用平台同时作为流数据管道是必要的。

By combining storage and low-latency subscriptions, streaming applications can treat both past and future data the same way. That is a single application can process historical, stored data but rather than ending when it reaches the last record it can keep processing as future data arrives. This is a generalized notion of stream processing that subsumes batch processing as well as message-driven applications.

基于存储和实时的订阅,串流应用可以以同样方式处理过去和未来的数据。这是一个单应用可以处理历史存储的数据,当历史数据处理完成后,应用将等待处理将要到达的数据而不是直接结束。这是一个关于包含批处理同时基于消息驱动应用的流式处理的广义的概念

Likewise for streaming data pipelines the combination of subscription to real-time events make it possible to use Kafka for very low-latency pipelines; but the ability to store data reliably make it possible to use it for critical data where the delivery of data must be guaranteed or for integration with offline systems that load data only periodically or may go down for extended periods of time for maintenance. The stream processing facilities make it possible to transform data as it arrives.

同样的,基于存储和实时事情的订阅,kafke作为流数据管道可以作为非常实时的管道;而可靠地存储数据使其可以处理关键数据,这些数据的交付必须有保障或与定期加载数据或可能长时间关闭维护的脱机系统相集成。流处理设备可以在数据到达时进行转换。

6.用例

6.1 消息

kafka可作为传统消息代理的代替品,消息代理用来解耦生产者和消费者,对比大多数据消息系统,kafka吞吐量更高,内置分区和副本及容错功能,这使得其成为大型可伸缩的消息处理应用的良好选择。
根据我们的经验,通信往往较低的吞吐量,但要求端到端的实时性及容错性保证,这些kafka都能提供。
在这一领域,kafka可以媲美传统的消息系统如activemq或rabbitmq

6.2 网站活动跟踪

kafka原生的用例能重构用户活动跟踪作为可订阅源数据,这意味着对于网站活动(页面浏览、搜索或用户的其它动作),每种动作类型将被输出到各自主题中。这些数据被订阅后,可供实时处理,实时监控,或加载到hadoop或离线数据仓库系统中进行离线处理并生成报表。

6.3 Metrics度量

Kafka is often used for operational monitoring data.
This involves aggregating statistics from distributed applications to produce centralized feeds of operational data.
kafka经常用来处理运营监控数据。这涉及从分布式应用中聚合统计数据以生成集中运营数据集

6.4 日志聚合Log Aggregation

许多人使用kafka作为日志聚合的替代品。日志聚合通常从服务器提取日志文件并统一存放以便处理(可能是文件服务器或HDFS)。kafka抽象出文件细节并提供对于日志或事件消息流的清晰抽像。这将使对多数据源及分布式数据消费的处理实时性更高并更容易。与日志中心系统Scribe或Flume相比,由于副本及更低的延时,kafka同样的高效与健壮。

6.5 流处理

kafka作为数据管理管道由多种场景组成。这些场景中,由kafka的主题作为原始输入,然后进行聚合、修饰或转换到新的主题中以便后续进一步的处理。
例如:处理管道可能从RSS中获取推送信息并发布到名为“articles”的主题中;后续结处理器将标准化并排重这些内容后,将这些清洗过的数据发送到一个新的题中;最终处理场景可能尝试推荐这些内容给用户。这种处理管道流程基于不同的主题生成了一个实时数据流式处理图。从0.10.0.0开始,一个名为Kafka Streams轻量但强大的流处理库用来处理以上操作。除Streams外,可供选择的开源工具包括Storm和Samza.

6.6 事件源

Event sourcing is a style of application design where state changes are logged as a time-ordered sequence of records.
事件源应用是一系列用来记录当状态发生改变时按次序保存记录日志。kafka可以保存大量日志数据使得其成为这类应用的一种优秀的后端。

6.7 系统Commit Log

Kafka可以作为分布式系统外部扩展的动作日志。这类日志用来同步节点之间数据,同时对于失败的节点可以借此恢复数据。kafka的日志压缩有助于此类操作。在这种作用场景下,Kafka与Apache BookKeeper比较相似。

posted @ 2016-10-13 11:08  mint_vip  阅读(270)  评论(0编辑  收藏  举报