自定义时间数据源继承SourceFunction
import java.util.Date
import org.apache.flink.streaming.api.functions.source.SourceFunction
class MySource extends SourceFunction[String]{
var flag = true
override def run(sourceContext: SourceFunction.SourceContext[String]): Unit = {
while (flag){
sourceContext.collect(new Date().getTime+"")
}
}
override def cancel(): Unit = {
flag = false
}
}
Flink读取时间数据源
import org.apache.flink.streaming.api.scala._
object ReadKafka {
def main(args: Array[String]): Unit = {
val env = StreamExecutionEnvironment.getExecutionEnvironment
val ds = env.addSource(new MySource)
ds.print()
env.execute()
}
}