我有一个由 byte[] 键控的主题,我想对其进行重新分区并通过消息正文中字段中的另一个键处理该主题。
我发现有KGroupedStream
and groupby
功能。但它需要一个聚合函数来转换为 KTable/KStream。我不需要聚合。我只想重新分区并处理输出。
是的你可以。您设置一个新密钥,然后通过另一个主题传输数据。
// repartition() will create the required topic automatically for your,
// with the same number of partitions as your input topic;
//
// it's also possible to set the number of partitions explicitly to scale in/out
// via `repartitioned(Repartitioned.numberOfPartitions(...))`
KStream stream = ...
KStream repartionedStream = stream.selectKey(...)
.repartition();
// older versions:
//
// using `through()` you need to create the use topic manually,
// before you start your application
KStream stream = ...
KStream repartionedStream = stream.selectKey(...)
.through("topic-name");
请注意,您需要创建您使用的主题through()
在启动具有所需分区数量的应用程序之前。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)