简体   繁体   English

将Kafka输入流动态连接到多个输出流

[英]Dynamically connecting a Kafka input stream to multiple output streams

Is there functionality built into Kafka Streams that allows for dynamically connecting a single input stream into multiple output streams? Kafka Streams内置了哪些功能,允许将单个输入流动态连接到多个输出流? KStream.branch allows branching based on true/false predicates, but this isn't quite what I want. KStream.branch允许基于真/假谓词的分支,但这不是我想要的。 I'd like each incoming log to determine the topic it will be streamed to at runtime, eg, a log {"date": "2017-01-01"} will be streamed to the topic topic-2017-01-01 and a log {"date": "2017-01-02"} will be streamed to the topic topic-2017-01-02 . 我希望每个传入的日志确定它将在运行时流式传输的主题,例如,日志{"date": "2017-01-01"}将流式传输到主题topic-2017-01-01和日志{"date": "2017-01-02"}将流式传输到主题topic-2017-01-02

I could call forEach on the stream, then write to a Kafka producer, but that doesn't seem very elegant. 我可以在流上调用forEach ,然后写给Kafka制作人,但这看起来并不优雅。 Is there a better way to do this within the Streams framework? 在Streams框架中有更好的方法吗?

If you want to create topics dynamically based on your data, you do not get any support within Kafka's Streaming API at the moment ( v0.10.2 and earlier). 如果您想根据数据动态创建主题,那么目前Kafka的Streaming API中没有任何支持( v0.10.2及更早版本)。 You will need to create a KafkaProducer and implement your dynamic "routing" by yourself (for example using KStream#foreach() or KStream#process() ). 您需要创建一个KafkaProducer并自己实现动态“路由”(例如使用KStream#foreach()KStream#process() )。 Note, that you need to do synchronous writes to avoid data loss (which are not very performant unfortunately). 请注意,您需要执行同步写入以避免数据丢失(不幸的是,这不是非常高性能)。 There are plans to extend Streaming API with dynamic topic routing, but there is no concrete timeline for this feature right now. 有计划使用动态主题路由扩展Streaming API,但目前此功能没有具体的时间表。

There is one more consideration you should take into account. 还有一个需要考虑的因素。 If you do not know your destination topic(s) ahead of time and just rely on the so-called "topic auto creation" feature, you should make sure that those topics are being created with the desired configuration settings (eg, number of partitions or replication factor). 如果您不提前知道目标主题并且只依赖于所谓的“主题自动创建”功能,则应确保使用所需的配置设置创建这些主题(例如,分区数量)或复制因子)。

As an alternative to "topic auto creation" you can also use Admin Client (available since v0.10.1 ) to create topics with correct configuration. 作为“主题自动创建”的替代方法,您还可以使用Admin Client(自v0.10.1 )来创建具有正确配置的主题。 See https://cwiki.apache.org/confluence/display/KAFKA/KIP-4+-+Command+line+and+centralized+administrative+operations 请参阅https://cwiki.apache.org/confluence/display/KAFKA/KIP-4+-+Command+line+and+centralized+administrative+operations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM