Kafka Streams处理延迟

时间:2019-10-19 11:53:10

标签: spring-boot apache-kafka apache-kafka-streams

我创建了一个Kafka Stream拓扑,我有1个Source和2个Sink。

我在Kafka Streams上使用Spring Boot(2.1.9),而不在使用Spring Cloud。 Kafka版本2.3.0

@Configuration
@EnableKafkaStreams
public class StreamStart {

    @Bean
    public KStream<String, String> process(StreamsBuilder builder) {
        KStream<String, String> inputStream = builder.stream("streamIn", Consumed.with(Serdes.String(), Serdes.String()));
        KStream<String, String> upperCaseStream = inputStream.mapValues(value -> value.toUpperCase());

        upperCaseStream.to("outTopic", Produced.with(Serdes.String(), Serdes.String()));

        KTable<String, Long> wordCounts = upperCaseStream
            .flatMapValues(v -> Arrays.asList(v.split(" ")))
            .selectKey((k, v) -> v)
            .groupByKey(Serialized.with(Serdes.String(), Serdes.String()))
            .count(Materialized.<String, Long, KeyValueStore<Bytes, byte[]>> as("counts-store"));

        wordCounts.toStream().to("wordCountTopic", Produced.with(Serdes.String(), Serdes.Long()));

        return upperCaseStream;
    }
}

数据瞬时流入 outTopic ,而显示在 wordCountTopic 中的数据则需要20-25秒。

有什么建议吗?

0 个答案:

没有答案