Shutting down Spark Streaming

时间:2016-05-17 12:27:15

标签: scala apache-spark apache-kafka spark-streaming

i'm new to Spark and i have one question.

I have Spark Streaming application which uses Kafka. Is there way to tell my application to shut down if new batch is empty (let's say batchDuration = 15 min)?

1 个答案:

答案 0 :(得分:1)

应该做的事情:

dstream.foreachRDD{rdd =>
    if (rdd.isEmpty) {
        streamingContext.stop()
    }
}

但要注意,根据您的应用程序工作流程,可能是第一批(或其间的某些批处理)也是空的,因此您的作业将在第一次运行时停止。您可能需要结合一些条件才能获得更可靠的停止。