Nonsense not to say, first, an example, a perceptual knowledge to introduce.
This example comes from the example of Spark's own, and the basic steps are as follows:
(1) Use the following command to enter a stream message:
$ nc-lk 9999
(2) Run Networkwordcount in a new terminal to count the number of words and output:
$ bin/run-example streaming.networkwordcount localhost 9999
(3) Type some content into the input process created in the first step and see the results in the terminal created in the second step, such as:
The contents of the first terminal input:
Hello World again
Output of the second port
-------------------------------------------
time:1436758706000 ms
-------------------------------------------
(again,1)
(hello,1)
(world,1)
To explain briefly, the above example prints the results by manually typing the content and passing it to spark streaming to count the number of words.
Attached code:
Package Org.apache.spark.examples.streamingimport Org.apache.spark.SparkConfimport org.apache.spark.streaming. {Seconds, streamingcontext}import org.apache.spark.storage.storagelevel/** * Counts words in UTF8 encoded, ' \ n ' Delimited text received from the network every second. * * Usage:networkwordcount
Spark Streaming Tutorials