From efe629b31db591699df52cb73c7542ecb42d74f3 Mon Sep 17 00:00:00 2001 From: Eno Thereska Date: Thu, 6 Jul 2017 14:02:08 +0100 Subject: [PATCH 1/5] Move quickstart under streams --- docs/quickstart.html | 161 +--------------------- docs/streams/quickstart.html | 249 +++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+), 160 deletions(-) create mode 100644 docs/streams/quickstart.html diff --git a/docs/quickstart.html b/docs/quickstart.html index 6509f75bed54..67902ed5db48 100644 --- a/docs/quickstart.html +++ b/docs/quickstart.html @@ -281,168 +281,9 @@

Step 8: Use

Kafka Streams is a client library of Kafka for real-time stream processing and analyzing data stored in Kafka brokers. -This quickstart example will demonstrate how to run a streaming application coded in this library. Here is the gist -of the WordCountDemo example code (converted to use Java 8 lambda expressions for easy reading). -

-
-// Serializers/deserializers (serde) for String and Long types
-final Serde<String> stringSerde = Serdes.String();
-final Serde<Long> longSerde = Serdes.Long();
-
-// Construct a `KStream` from the input topic ""streams-file-input", where message values
-// represent lines of text (for the sake of this example, we ignore whatever may be stored
-// in the message keys).
-KStream<String, String> textLines = builder.stream(stringSerde, stringSerde, "streams-file-input");
-
-KTable<String, Long> wordCounts = textLines
-    // Split each text line, by whitespace, into words.
-    .flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))
-
-    // Group the text words as message keys
-    .groupBy((key, value) -> value)
-
-    // Count the occurrences of each word (message key).
-    .count("Counts")
-
-// Store the running counts as a changelog stream to the output topic.
-wordCounts.to(stringSerde, longSerde, "streams-wordcount-output");
-
- -

-It implements the WordCount -algorithm, which computes a word occurrence histogram from the input text. However, unlike other WordCount examples -you might have seen before that operate on bounded data, the WordCount demo application behaves slightly differently because it is -designed to operate on an infinite, unbounded stream of data. Similar to the bounded variant, it is a stateful algorithm that -tracks and updates the counts of words. However, since it must assume potentially -unbounded input data, it will periodically output its current state and results while continuing to process more data -because it cannot know when it has processed "all" the input data. -

-

-As the first step, we will prepare input data to a Kafka topic, which will subsequently be processed by a Kafka Streams application. -

- - - -
-> echo -e "all streams lead to kafka\nhello kafka streams\njoin kafka summit" > file-input.txt
-
-Or on Windows: -
-> echo all streams lead to kafka> file-input.txt
-> echo hello kafka streams>> file-input.txt
-> echo|set /p=join kafka summit>> file-input.txt
-
- -

-Next, we send this input data to the input topic named streams-file-input using the console producer, -which reads the data from STDIN line-by-line, and publishes each line as a separate Kafka message with null key and value encoded a string to the topic (in practice, -stream data will likely be flowing continuously into Kafka where the application will be up and running): -

- -
-> bin/kafka-topics.sh --create \
-    --zookeeper localhost:2181 \
-    --replication-factor 1 \
-    --partitions 1 \
-    --topic streams-file-input
-
- - -
-> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic streams-file-input < file-input.txt
-
- -

-We can now run the WordCount demo application to process the input data: -

- -
-> bin/kafka-run-class.sh org.apache.kafka.streams.examples.wordcount.WordCountDemo
-
- -

-The demo application will read from the input topic streams-file-input, perform the computations of the WordCount algorithm on each of the read messages, -and continuously write its current results to the output topic streams-wordcount-output. -Hence there won't be any STDOUT output except log entries as the results are written back into in Kafka. -The demo will run for a few seconds and then, unlike typical stream processing applications, terminate automatically. -

-

-We can now inspect the output of the WordCount demo application by reading from its output topic: -

- -
-> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 \
-    --topic streams-wordcount-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.LongDeserializer
-
- -

-with the following output data being printed to the console: -

- -
-all     1
-lead    1
-to      1
-hello   1
-streams 2
-join    1
-kafka   3
-summit  1
-
- -

-Here, the first column is the Kafka message key in java.lang.String format, and the second column is the message value in java.lang.Long format. -Note that the output is actually a continuous stream of updates, where each data record (i.e. each line in the original output above) is -an updated count of a single word, aka record key such as "kafka". For multiple records with the same key, each later record is an update of the previous one. -

- -

-The two diagrams below illustrate what is essentially happening behind the scenes. -The first column shows the evolution of the current state of the KTable<String, Long> that is counting word occurrences for count. -The second column shows the change records that result from state updates to the KTable and that are being sent to the output Kafka topic streams-wordcount-output. -

- - - - -

-First the text line “all streams lead to kafka” is being processed. -The KTable is being built up as each new word results in a new table entry (highlighted with a green background), and a corresponding change record is sent to the downstream KStream. -

-

-When the second text line “hello kafka streams” is processed, we observe, for the first time, that existing entries in the KTable are being updated (here: for the words “kafka” and for “streams”). And again, change records are being sent to the output topic. -

-

-And so on (we skip the illustration of how the third line is being processed). This explains why the output topic has the contents we showed above, because it contains the full record of changes. -

- -

-Looking beyond the scope of this concrete example, what Kafka Streams is doing here is to leverage the duality between a table and a changelog stream (here: table = the KTable, changelog stream = the downstream KStream): you can publish every change of the table to a stream, and if you consume the entire changelog stream from beginning to end, you can reconstruct the contents of the table. -

- -

-Now you can write more input messages to the streams-file-input topic and observe additional messages added -to streams-wordcount-output topic, reflecting updated word counts (e.g., using the console producer and the -console consumer, as described above). +This quickstart example will demonstrate how to run a streaming application coded in this library.

-

You can stop the console consumer via Ctrl-C.

diff --git a/docs/streams/quickstart.html b/docs/streams/quickstart.html new file mode 100644 index 000000000000..ab8f858a2ae6 --- /dev/null +++ b/docs/streams/quickstart.html @@ -0,0 +1,249 @@ + + + + + +
+ + + +
+ +
+ + +
+
+
+ + From 5a9829dfe552983acff4b778d32afa74cc4a77e4 Mon Sep 17 00:00:00 2001 From: Eno Thereska Date: Fri, 7 Jul 2017 14:17:38 +0100 Subject: [PATCH 2/5] Addressed comments --- docs/documentation/streams/quickstart.html | 19 +++++++++++++++ docs/quickstart.html | 8 +++++-- docs/streams/core-concepts.html | 2 +- docs/streams/index.html | 5 +++- docs/streams/quickstart.html | 27 ++++++++++++++-------- 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 docs/documentation/streams/quickstart.html diff --git a/docs/documentation/streams/quickstart.html b/docs/documentation/streams/quickstart.html new file mode 100644 index 000000000000..f69c0d5ae755 --- /dev/null +++ b/docs/documentation/streams/quickstart.html @@ -0,0 +1,19 @@ + + + + diff --git a/docs/quickstart.html b/docs/quickstart.html index 67902ed5db48..3652154e5ae6 100644 --- a/docs/quickstart.html +++ b/docs/quickstart.html @@ -280,8 +280,12 @@

Step 7: Use

Step 8: Use Kafka Streams to process data

-Kafka Streams is a client library of Kafka for real-time stream processing and analyzing data stored in Kafka brokers. -This quickstart example will demonstrate how to run a streaming application coded in this library. + Kafka Streams is a client library for building mission-critical real-time applications and microservices, + where the input and/or output data is stored in Kafka clusters. Kafka Streams combines the simplicity of + writing and deploying standard Java and Scala applications on the client side with the benefits of Kafka's + server-side cluster technology to make these applications highly scalable, elastic, fault-tolerant, distributed, + and much more. This quickstart example will demonstrate how + to run a streaming application coded in this library.

diff --git a/docs/streams/core-concepts.html b/docs/streams/core-concepts.html index b50495d652ff..80af1c0e6359 100644 --- a/docs/streams/core-concepts.html +++ b/docs/streams/core-concepts.html @@ -135,7 +135,7 @@

Pr

diff --git a/docs/streams/index.html b/docs/streams/index.html index 013494b2f039..b1117e6461f5 100644 --- a/docs/streams/index.html +++ b/docs/streams/index.html @@ -21,6 +21,9 @@

Streams

    +
  1. + Quickstart +
  2. Core Concepts
  3. @@ -67,7 +70,7 @@

    Overview

    diff --git a/docs/streams/quickstart.html b/docs/streams/quickstart.html index ab8f858a2ae6..00f16de1b3c9 100644 --- a/docs/streams/quickstart.html +++ b/docs/streams/quickstart.html @@ -21,14 +21,21 @@

    Kafka Streams Library Quickstart

    This tutorial assumes you are starting fresh and have no existing Kafka or ZooKeeper data. However, if you have already started Kafka and - Zookeeper, feel free to skip the first two steps + Zookeeper, feel free to skip the first two steps. +

    -Kafka Streams is a client library of Kafka for real-time stream processing and analyzing data stored in Kafka brokers. + Kafka Streams is a client library for building mission-critical real-time applications and microservices, + where the input and/or output data is stored in Kafka clusters. Kafka Streams combines the simplicity of + writing and deploying standard Java and Scala applications on the client side with the benefits of Kafka's + server-side cluster technology to make these applications highly scalable, elastic, fault-tolerant, distributed, + and much more. +

    +

    This quickstart example will demonstrate how to run a streaming application coded in this library. Here is the gist of the WordCountDemo example code (converted to use Java 8 lambda expressions for easy reading).

    -
    +
     // Serializers/deserializers (serde) for String and Long types
     final Serde<String> stringSerde = Serdes.String();
     final Serde<Long> longSerde = Serdes.Long();
    @@ -73,7 +80,7 @@ 

    Step > tar -xzf kafka_2.11-0.10.2.0.tgz > cd kafka_2.11-0.10.2.0

    - +

    Step 2: Start the Kafka server

    @@ -93,7 +100,7 @@

    Step 3: Prepare data

    @@ -138,9 +145,7 @@

    Step 3 > bin/kafka-console-producer.sh --broker-list localhost:9092 --topic streams-file-input < file-input.txt

    -

    Step 4: Process data

    -

     > bin/kafka-run-class.sh org.apache.kafka.streams.examples.wordcount.WordCountDemo
    @@ -202,7 +207,7 @@ 

    Step 4 The KTable is being built up as each new word results in a new table entry (highlighted with a green background), and a corresponding change record is sent to the downstream KStream.

    -When the second text line “hello kafka streams” is processed, we observe, for the first time, that existing entries in the KTable are being updated (here: for the words “kafka” and for “streams”). And again, change records are being sent to the output topic. +When the second text line “hello kafka streams” is processed, we observe, for the first time, that existing entries in the KTable are being updated (here: for the words "kafka" and for "streams"). And again, change records are being sent to the output topic.

    And so on (we skip the illustration of how the third line is being processed). This explains why the output topic has the contents we showed above, because it contains the full record of changes. @@ -220,11 +225,15 @@

    Step 4

    You can stop the console consumer via Ctrl-C.

    +
    - +
    From c93f0e9f81e00ba8e480b17b73220fe05ed6167c Mon Sep 17 00:00:00 2001 From: Eno Thereska Date: Fri, 7 Jul 2017 14:18:23 +0100 Subject: [PATCH 3/5] Typo --- docs/streams/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/streams/index.html b/docs/streams/index.html index b1117e6461f5..8791a93fa4c3 100644 --- a/docs/streams/index.html +++ b/docs/streams/index.html @@ -22,7 +22,7 @@

    Streams

    1. - Quickstart + Quickstart
    2. Core Concepts From c732761236595080622d55bfd45fcae01854ce01 Mon Sep 17 00:00:00 2001 From: Eno Thereska Date: Fri, 7 Jul 2017 15:02:13 +0100 Subject: [PATCH 4/5] Fix .. --- docs/streams/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/streams/index.html b/docs/streams/index.html index 8791a93fa4c3..b930afb271fa 100644 --- a/docs/streams/index.html +++ b/docs/streams/index.html @@ -15,7 +15,7 @@ limitations under the License. --> - + - - + +
      - +
      - +