访问阿里云首页面:https://www.aliyun.com/



选择"按量付费"

通过选择区域,看哪个区域有虚拟交换机。


查看创建的工作空间,当工作空间状态为运行中时,点击控制台。


开通完成后,会有一个控制台:

可以选择SQL开发或者作业运维运行自己的Flink程序。
java
package com.bigdata.day06;
import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;
import java.util.Random;
/**
* @基本功能:
* @program:FlinkDemo
* @author: 闫哥
* @create:2023-11-24 14:34:50
**/
public class _03TestAliyun {
public static void main(String[] args) throws Exception {
//1. env-准备环境
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setRuntimeMode(RuntimeExecutionMode.AUTOMATIC);
//2. source-加载数据
DataStreamSource<String> dataStreamSource = env.addSource(new SourceFunction<String>() {
@Override
public void run(SourceContext<String> ctx) throws Exception {
String[] words = {"hello", "world", "bigdata"};
Random random = new Random();
while (true) {
String word = words[random.nextInt(words.length)];
int num = random.nextInt(10);
ctx.collect(word + "," + num);
Thread.sleep(500);
}
}
@Override
public void cancel() {
}
});
//3. transformation-数据处理转换
//2. source-加载数据
SingleOutputStreamOperator<Tuple2<String, Integer>> mapStream = dataStreamSource.map(new MapFunction<String, Tuple2<String, Integer>>() {
@Override
public Tuple2<String, Integer> map(String s) throws Exception {
String[] arr = s.split(",");
return Tuple2.of(arr[0], Integer.valueOf(arr[1]));
}
});
//3. transformation-数据处理转换
SingleOutputStreamOperator<Tuple2<String, Integer>> result = mapStream.keyBy(0).sum(1);
result.print();
//4. sink-数据输出
//5. execute-执行
env.execute();
}
}
作业运维在本地IDEA开发,将jar包上传。




可以通过 UI 界面查看效果:

有些程序,是需要环境的,假如数据需要依赖我们虚拟机的环境,是没办法在flink上运行的,因为flink访问不到虚拟机的服务,可以写死一些数据,比如自定义数据源,或者写死一些数据,进行测试。
第一次可以无状态启动:

查看Flink自带的UI界面:

创建快照:

停止后重启,可以从某个快照进行重启:

查看运行结果:

以下是帮助文档: