我已经使用Apache Kafka和Apache Spark结构化流构建了一个应用程序。我正面临以下问题。
场景:
清除检查点位置后,我希望流中只有新消息。
Spark版本:2.4.0,
Kafka客户端版本:2.0.0,
Kafka版本:2.0.0,
集群管理器:Kubernetes
我通过更改检查点位置来尝试这种情况,但是问题仍然存在。
{
SparkConf sparkConf = new SparkConf().setAppName("SparkKafkaConsumer");
SparkSession spark = SparkSession.builder().config(sparkConf).getOrCreate();
Dataset<Row> stream = spark
.readStream()
.format("kafka")
.option("kafka.bootstrap.servers", "localhost:9092")
.option(subscribeType, "REQUEST_TOPIC")
.option("failOnDataLoss",false)
.option("maxOffsetsPerTrigger","50")
.option("startingOffsets","latest")
.load()
.selectExpr(
"CAST(value AS STRING) as payload",
"CAST(key AS STRING)",
"CAST(topic AS STRING)",
"CAST(partition AS STRING)",
"CAST(offset AS STRING)",
"CAST(timestamp AS STRING)",
"CAST(timestampType AS STRING)");
DataStreamWriter<String> dataWriterStream = stream
.writeStream()
.format("kafka")
.option("kafka.bootstrap.servers", "localhost:9092")
.option("kafka.max.request.size", "35000000")
.option("kafka.retries", "5")
.option("kafka.batch.size", "35000000")
.option("kafka.receive.buffer.bytes", "200000000")
.option("kafka.acks","0")
.option("kafka.compression.type", "snappy")
.option("kafka.linger.ms", "0")
.option("kafka.buffer.memory", "50000000")
.option("topic", "RESPONSE_TOPIC")
.outputMode("append")
.option("checkpointLocation", checkPointDirectory);
spark.streams().awaitAnyTermination();
}
答案 0 :(得分:1)
检查下面的链接,
https://jaceklaskowski.gitbooks.io/mastering-apache-spark/spark-rdd-checkpointing.html
您调用SparkContext.setCheckpointDir(directory:String)来设置检查点目录-RDD被检查点所在的目录。如果在群集上运行,该目录必须是HDFS路径。原因是驱动程序可能会尝试从其自己的本地文件系统重建检查点RDD,这是不正确的,因为检查点文件实际上位于执行程序机器上