设置checkpoint存储目录,从最新的checkpoint恢复:
JavaStreamingContext ssc = JavaStreamingContext.getOrCreate(checkpointDirectory,
()-> createContext(ip,port,outputPath,checkpointDirectory));
createContext(String ip, int port, String outputPath, String checkpointDirectory):
public static JavaStreamingContext createContext(String ip, int port, String outputPath, String checkpointDirectory) {
//程序第一运行时会创建该条语句,如果应用程序失败,则会从checkpoint中恢复,该条语句不会执
SparkConf sparkConf = new SparkConf().setAppName("RecoverableNetworkWordCount").setMaster("local");
// Create the context with a 1 second batch size
JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, Durations.seconds(1));
ssc.checkpoint(checkpointDirectory);
return ssc;
}