跨多个用户扩展 Kafka 流应用程序

Scaling Kafka stream application across multiple users

我有一个设置,我将事件推送到 kafka,然后 运行 同一个集群上的 Kafka Streams 应用程序。可以说扩展 Kafka Streams 应用程序的唯一方法是通过添加节点或增加 Partitions 来扩展 kafka 集群本身吗?

在那种情况下,我如何确保我的消费者不会关闭集群并确保关键管道始终 "on"。有什么 Topology Priority 的概念可以避免可能的停机时间吗?我希望能够在不影响核心管道的情况下向任何人公开流以构建应用程序。如果解决方案是设置另一个 kafka 集群,那么对所有临时查询使用 Apache storm 是否更有意义? (我知道很多消费者仍然会导致 kafka 集群出现问题,但至少 topology 处理现在是独立的)

不建议 运行 您的 Streams 应用程序与您的代理位于同一服务器上(即使这在技术上是可行的)。 Kafka 的 Streams API 提供了一种 application-based 方法——而不是 cluster-based 方法 —— 因为它是一个库而不是一个框架。

无需扩展 Kafka 集群即可扩展您的 Streams 应用程序。通常,Streams 应用程序的并行度受应用程序输入主题的分区数限制。建议 over-partition 您的主题(此开销相当小)以防止缩放限制。

因此,"offer anyone to build applications" 更简单,因为每个人都拥有自己的应用程序。无需将应用程序提交到集群。它们可以在您喜欢的任何地方执行(因此,每个团队都可以像部署他们拥有的任何其他应用程序一样部署他们的 Streams 应用程序)。因此,您有许多部署选项,从 WAR 文件到 YARN/Mesos 到容器(如 Kubernetes)。最适合你的。

即使 Flink、Storm 或 Samza 等框架提供集群管理,您也只能使用与这些框架集成的工具(例如,Samza 需要 YARN——没有其他可用选项)。假设您已经有一个 Mesos 设置,您可以将它重新用于您的 Kafka Streams 应用程序——不需要专用的 "Kafka Streams cluster"(因为没有这样的东西)。

An application’s processor topology is scaled by breaking it into multiple tasks.

More specifically, Kafka Streams creates a fixed number of tasks based on the input stream partitions for the application, with each task assigned a list of partitions from the input streams (i.e., Kafka topics).

The assignment of partitions to tasks never changes so that each task is a fixed unit of parallelism of the application. Tasks can then instantiate their own processor topology based on the assigned partitions; they also maintain a buffer for each of its assigned partitions and process messages one-at-a-time from these record buffers.

As a result stream tasks can be processed independently and in parallel without manual intervention.

It is important to understand that Kafka Streams is not a resource manager, but a library that “runs” anywhere its stream processing application runs. Multiple instances of the application are executed either on the same machine, or spread across multiple machines and tasks can be distributed automatically by the library to those running application instances.

The assignment of partitions to tasks never changes; if an application instance fails, all its assigned tasks will be restarted on other instances and continue to consume from the same stream partitions.

流的处理发生在应用程序所在的机器上 运行。

我推荐你看看this guide,它可以帮助你更好地理解Kafka Streams的工作方式。