简体   繁体   English

Kafka输出流

[英]Kafka output stream

I've been working with the kafka consumer- and producer api for a while now and want to try my hand at the streams api. 我已经使用kafka消费者和生产者api已有一段时间了,想尝试一下stream api。 I've looked at a ton of references online but I cant figure out this one simple thing. 我在网上看了很多参考资料,但我想不通这简单的事情。

How do you make a KStream that only sends messages to an output topic. 如何制作仅将消息发送到输出主题的KStream。

Take for instance this most basic example they have on the github repo: https://github.com/confluentinc/examples/blob/3.2.x/kafka-streams/src/main/java/io/confluent/examples/streams/WordCountLambdaExample.java It takes messages from one queue and posts them to a different one after manipulating it. 例如,他们在github仓库上有这个最基本的示例: https : //github.com/confluentinc/examples/blob/3.2.x/kafka-streams/src/main/java/io/confluent/examples/streams/ WordCountLambdaExample.java它从一个队列中获取消息,并在操作后将其发布到另一个队列中。

Something like this: 像这样:

final KStreamBuilder builder = new KStreamBuilder();
final KStream<String, String> textLines = builder.stream();
// do the dirty work...
textLines.to("outputTopic") 

But builder.stream(); 但是builder.stream(); does not exists it needs at the very least a input topic name. 不存在,它至少需要输入主题名称。

Should I just stick to a regular kafka producer for this? 我是否应该为此坚持做普通的卡夫卡生产商? If so I have had no luck finding a resource that says this explicitly. 如果是这样,我没有运气找到明确说明这一点的资源。

Kafka Streams API is designed to consume topics as input streams, process the records, and write the results back to topics. Kafka Streams API旨在将主题用作输入流,处理记录并将结果写回主题。 It's not designed to just write data to Kafka. 它并非旨在仅将数据写入Kafka。

So yes, you should use KafkaProducer if you want to write data to a topic. 因此,是的,如果要将数据写入主题,则应使用KafkaProducer

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

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