显示Flink界面三种方式

idea方式一:

a)添加flink-dist包

 

 

 

 

 b)代码

import com.example.demo.flink.impl.SplitWordFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @program: demo
 * @description: wordcount
 * @author: yang
 * @create: 2020-12-28 16:52
 */
public class WordCount {

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

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

//        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        env.setParallelism(2);

        String hostname = "192.168.75.101";
        int port = 5000;

        DataStreamSource<String> dataStream = env.socketTextStream(hostname, port);

        SingleOutputStreamOperator<Tuple2<String, Integer>> result = dataStream.flatMap(new SplitWordFunction()).keyBy(0).sum(1);

        result.print();

        env.execute("test word count");

    }
}

c)启动5000端口

nc -l 5000 -v

d) 启动flink对应的main函数

 

 e) 打开界面

 

 方式二:

方式二比方式一方便点,但是方式二一般用于本地测试,方式一可用于生产

a) 环境改为web 

 

 b)代码

import com.example.demo.flink.impl.SplitWordFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @program: demo
 * @description: wordcount
 * @author: yang
 * @create: 2020-12-28 16:52
 */
public class WordCount {

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

        //StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        env.setParallelism(2);

        String hostname = "192.168.75.101";
        int port = 5000;

        DataStreamSource<String> dataStream = env.socketTextStream(hostname, port);

        SingleOutputStreamOperator<Tuple2<String, Integer>> result = dataStream.flatMap(new SplitWordFunction()).keyBy(0).sum(1);

        result.print();

        env.execute("test word count");

    }
}

方式三:

方式三通过flink安装包查看界面

./start-cluster.bat  或
./start-cluster.sh

 

posted @ 2020-12-29 15:49  小白啊小白,Fighting  阅读(1536)  评论(0编辑  收藏  举报