Kafka 流 API 中的任务有何用途

What purpose do tasks in Kafka streams API serve

我正在尝试了解 Kafka 流的架构 API 并在 documentation:

中遇到了这个

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

将处理器拓扑分解为任务的所有标准是什么?它只是 stream/topic 中的分区数还是更多。

Tasks can then instantiate their own processor topology based on the assigned partitions

有人可以举例说明上面的意思吗?如果任务只是为了扩展而创建的,那么它们不应该都具有相同的拓扑结构吗?

任务是原子并行处理单元。

一个拓扑分为sub-topologies(sub-topologies是转发数据的“连通分量”in-memory;不同的sub-topologies通过主题相连)。对于每个 sub-topology,输入主题分区的数量决定了创建的任务数量。如果有多个输入主题,则所有主题的最大分区数决定了任务数。

如果你想知道你的 Kafka Streams 应用程序的 sub-topologies,你可以调用 Topology#describe():返回的 TopologyDescription 可以通过 toString() 打印或者可以遍历 sub-topologies 及其对应的 DAG。


Kafka Streams 应用程序具有一种拓扑结构,该拓扑结构可能具有一个或多个 sub-topologies。您可以在文章 Data Reprocessing with the Streams API in Kafka: Resetting a Streams Application.

中找到具有 2 sub-topologies 的拓扑