20161116spark-streaming Demo

Source: Internet
Author: User
spark-streaming Demo Add Dependency
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactid>spark-core_2.10 </artifactId>
        <version>2.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactid>spark-streaming_2.10</artifactid >
        <version>2.0.2</version>
    </dependency>

Note: The above version of debug passes, other versions may have jar package dependency conflict issues. Code

Import Java.util.Arrays;
Import Java.util.Iterator;

Import Java.util.regex.Pattern;
Import org.apache.spark.api.java.function.FlatMapFunction;
Import org.apache.spark.streaming.Duration; Import Scala.

Tuple2;

Import org.apache.spark.SparkConf;
Import Org.apache.spark.api.java.function.Function2;
Import org.apache.spark.api.java.function.PairFunction;
Import Org.apache.spark.api.java.StorageLevels;
Import org.apache.spark.streaming.Durations;
Import Org.apache.spark.streaming.api.java.JavaDStream;
Import Org.apache.spark.streaming.api.java.JavaPairDStream;
Import Org.apache.spark.streaming.api.java.JavaReceiverInputDStream;

Import Org.apache.spark.streaming.api.java.JavaStreamingContext;

public class Javanetworkwordcount {private static final Pattern SPACE = Pattern.compile ("");  public static void Main (string[] args) throws Exception {if (Args.length < 2) {System.err.println ("Usage:
        Javanetworkwordcount  
specify IP and port as arguments to the main function 
localhost 1111

Note: In particular, it is important to be aware that the VM options must be specified as-dspark.master=local, otherwise the spark task will not start normally and the maser URL error is not specified. NC boot port and send data

Enter the NC LK 1111 in the console and enter a series of text returns to see the number of individual words we have counted.
As shown in the following illustration:

attached to the official code

Note: The official code is problematic and needs to be adjusted
https://github.com/apache/spark/blob/v2.0.2/examples/src/main/java/org/apache/spark/examples/streaming/ Javanetworkwordcount.java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.