Flink Example: Monitoring the wikipedia Edit Stream

Flink Example: Monitoring the wikipedia Edit Stream

官网链接:https://ci.apache.org/projects/flink/flink-docs-release-1.6/quickstart/run_example_quickstart.html

demo:

package wikiedits;

import org.apache.flink.api.common.typeinfo.TypeHint;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.connectors.wikiedits.WikipediaEditEvent;
import org.apache.flink.streaming.connectors.wikiedits.WikipediaEditsSource;

public class WikipediaAnalysis {
    public static void main(String[] args) throws Exception{

        StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream edits = see.addSource(new WikipediaEditsSource());

        KeyedStream keyedEdits = edits
                .keyBy(WikipediaEditEvent::getUser);

        DataStream> result = keyedEdits
                .map((event) -> new Tuple2<>(event.getUser(), Long.valueOf(event.getByteDiff())))
                .returns(new TypeHint>(){})
                .timeWindowAll(Time.seconds(5))
                .reduce((acc, a) -> new Tuple2<>(a.f0, acc.f1+a.f1));

        result.print();
        see.execute();
    }
}

问题:

  1. Mac idea 直接运行时 接受网络超时,可能是公司网问题。回家重试排查下。
  2. Maven 依赖有问题 无奈之下 rm repository->重新 下载

你可能感兴趣的:(Flink Example: Monitoring the wikipedia Edit Stream)