是我的代码段。我想并行化卡夫卡流处理。但我不想放入Runnable,也不想多次启动此应用程序。
有没有类似stream.parallel()的方式?
final Serde<String> stringSerde = Serdes.String();
Consumed<String, String> types = Consumed.with(stringSerde, stringSerde);
//create StreamFactory
StreamsBuilder builder = new StreamsBuilder();
//read message from topic
KStream<String, String> xmlMessages = builder.stream("from_topic", types);
//select matched messages
KStream<String, String> matchedMessages = xmlMessages.filter((key, xmlMessageValue) -> {
//here does the filter tasks
});
//dispatch matched message to destination topic
matchedMessages.to("to_topic");
KafkaStreams streams = new KafkaStreams(builder.build(), props);
streams.start();
Runtime.getRuntime().addShutdownHook(new Thread(streams::close));
答案 0 :(得分:1)
您可以通过将num.stream.threads
设置为大于默认值1的值来运行多线程流。
Kafka将在内部处理多线程,无需更改应用程序代码(启动其他流或可运行对象)。
但是请注意