As a first step to start all applications, you need to start the Zookeeper and the Kafka.
Download the 2.2.0 release and un-tar it.
> bin\windows\zookeeper-server-start.bat config\zookeeper.properties> bin\windows\kafka-server-start.bat config\server.propertiesImplementation of WordCount algorithm, which returns a list of all unique words from the input text and their number of occurrences.
Create the input topic named word-count-input and the output topic named word-count-output:
> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic word-count-input
> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic word-count-outputStart the console producer:
> bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic word-count-inputStart the console consumer in a separate terminal:
> bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic word-count-output --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property key.deserializer=org.apache.kafka.common.serialization.StringDeserializer --property value.deserializer=org.apache.kafka.common.serialization.LongDeserializerRun the WordCount java application.
Let's write a message with the console producer into the input topic word-count-input and check the output word count which will be written to the word-count-output topic and printed by the console consumer:
> bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic word-count-input
Hello world
This is Kafka Streams appThis application counts and displays the colours and the number of people who consider a particular colour as their favorite. It is assumed that people can change their preferences.
Create the input topic named fav-colour-input and the output topic named fav-colour-output:
> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic fav-colour-input
> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic fav-colour-outputStart the console producer:
> bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic fav-colour-inputStart the console consumer in a separate terminal:
> bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic fav-colour-output --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property key.deserializer=org.apache.kafka.common.serialization.StringDeserializer --property value.deserializer=org.apache.kafka.common.serialization.LongDeserializerRun the FavouriteColour java application.
As input, the application accepts name, colour pairs. Let's write a message with the console producer into the input topic fav-colour-input and check the output data which will be written to the fav-colour-output topic and printed by the console consumer:
> bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic fav-colour-input
ann, green
alex, blue
ann, blueDemonstration of the exactly once semantics on the example of bank transactions.
Create a topic named bank-transactions in which the producer will write the generated transactions and the output topic named bank-balance:
> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic bank-transactions
> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic bank-balanceRun the console consumer for the topic that displays the generated transactions and for the topic that displays the current balance:
> bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic bank-transactions --from-beginning
> bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic bank-balance --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property key.deserializer=org.apache.kafka.common.serialization.StringDeserializer --property value.deserializer=org.apache.kafka.common.serialization.StringDeserializerThe producer generates user transaction json objects that contain the name, time of the transaction, and random amount from -100 to 100.
The application generates a json object with the number of user transactions, current balance and time of the last transaction.