Exercise: Word Count Per Record
Write a new Kafka application WordCountPerLineApp (using Kafka Producer and Consumer APIs) that does the following:
- Consume records from a topic, e.g.
input
. - Count words (in the value of a record).
- Produce records with the unique words and their occurrences (counts).
- A record
key -> hello hello world
gives a record with the following valuehello -> 2, world -> 1
(and the same key as in the input record).
- A record
(EXTRA)
- Produces as many records as there are unique words in the input record with their occurrences (counts)
- A record
key -> hello hello world
gives two records in the output, i.e.(hello, 2) and (world, 1 (as (key, value))
- A record