Kafka WordCount问题

时间:2018-08-18 07:18:08

标签: apache-kafka-streams

嗨,我正在尝试运行基本的Kafka字数统计问题,问题是计数(值)未在控制台上打印

KStream<String, String> textLines = builder.stream("word-count-input");
      KTable<String, Long> wordCounts = textLines

              .mapValues(textLine -> textLine.toLowerCase())
              .mapValues(String::toLowerCase)
              .flatMapValues(textLine -> Arrays.asList(textLine.split("\\W+")))
              .selectKey((key, word) -> word)
              .groupByKey()
              .count("Counts");

      wordCounts.to(Serdes.String(), Serdes.Long(), "word-count-output");

控制台生产者:

bin/kafka-console-producer.sh  --broker-list localhost:9092  --topic word-count-input

控制台使用者:

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic word-count-output --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property key.deserailizer=org.apache.kafka.common.serialization.StringDeserializer -propertykey.deserailizer=org.apache.kafka.common.serialization.LongDeserialzer

但是在输出中我没有得到输入的计数

输入:

This is Kafka
Kafka is awesome
Kafka Kafka Kafka

预期产量

this 1
is 1
kafka 1
kafka 2
is 2
awesome 1
kafka 3
kafka 4

实际输出

this 
is 
kafka 
kafka 
is 
awesome 
kafka 
kafka 

1 个答案:

答案 0 :(得分:2)

您的控制台使用者命令中有错别字key.deserailizer和value.deserailizer。