一、我们知道sparkstreaming如何想实现Exactly Once语义,需要借助mysql这种事务型数据库来实现,具体实现方式可以参考:https://blog.csdn.net/wangpei1949/article/details/89277490
二、那么StructStreaming想实现Exactly Once语义也需要借助MySQL吗,答案是否,那么具体是怎么实现的呢?参考:https://zhuanlan.zhihu.com/p/68393447
三、实际上Structured Streaming消费Kafka时并不会将Offset提交到Kafka集群,我们写入到sink的时候,必须要设置一个checkpointLocaion,Structured Streaming就是在这个目录下来管理offset(这篇文章提供了三种方式:https://blog.csdn.net/wangpei1949/article/details/105187210)。
我们举例第二种实现方式
# Write key-value data from a DataFrame to a Kafka topic specified in an option
query = df \
.selectExpr("CAST(userId AS STRING) AS key", "to_json(struct(*)) AS value") \
.writeStream \
.format("kafka") \
.option("kafka.bootstrap.servers", "host1:port1,host2:port2") \
.option("topic", "topic1") \
.option("checkpointLocation", "/path/to/HDFS/dir") \
.start()
如果程序中断之后再重启,虽然在读入流的时候设置的是某一个offset,但是在写入流的时候,如果已经存在了checkpointLocation,那么流会从之前中断的地方继续处理,即读入流对offset的设置只是针对checkpointLocation第一次初始化的时候有效。
官网文档:https://spark.apache.org/docs/latest/structured-streaming-kafka-integration.html
https://blog.csdn.net/bingospunky/article/details/90409275
structstreaming详解:https://zhuanlan.zhihu.com/p/51883927
sparkstreaming如何保证eos:https://www.yuque.com/polaris-docs/bigdata/spark-eos?language=en-us
还在把offset存ZooKeeper吗?Structured Streaming checkpoint可以这么用 https://toutiao.io/posts/tb0shcr/preview