import org.apache.flink.streaming.api.functions.source.RichSourceFunction; import java.util.concurrent.TimeUnit; public class DynamicSource extends RichSourceFunction<String> { private volatile boolean isRunning = true; @Override public void run(SourceContext<String> ctx) throws Exception { while (isRunning) { TimeUnit.SECONDS.sleep(5000); ctx.collect("1"); } } @Override public void cancel() { isRunning = false; } }
DataStreamSource<String> stringDataStreamSource = env.addSource(new DynamicSource());
原文:http://www.cicis.com.cn/f50a219636404954beedc83279fbf304.htmlhtml