Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Kafka Streams - not able to see the text in console consumer

Highlighted

Kafka Streams - not able to see the text in console consumer

Expert Contributor

Hello All

- i've a basic word count Kafka streams code, which reads data from the input topic, splits the data (per the separator) and outputs the data into the output topic.

I've a console producer, which is putting data into the input topic (kstreams3), and a console consumer which is reading the (split) data from output topic(kstreams4)..

The code seems to be working fine, but on the console consumer, i'm Not able to see the text.

It seems to be printing blanks, instead of the actual text .. (though, console consumer seems to be consuming the correct number of lines)

Any pointers on what the issue is ?

Code ->

Properties props = new Properties();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streamswordcount-application");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
props.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());

KStreamBuilder builder = new KStreamBuilder();
KStream<String, String> textLines = builder.stream("kstreams3"); 

KTable<String, Long> wordCounts = textLines
.flatMapValues(textLine -> Arrays.asList(textLine.toLowerCase().split("\\W+")))
.groupBy((key, word)-> word)
.count("Counts");

System.out.println(" Kstreams - wordCount " + wordCounts);

wordCounts.to(Serdes.String(),Serdes.Long(),"kstreams4");

KafkaStreams streams = new KafkaStreams(builder, props);
streams.start();