Apache spark 将Spark结构化流式输出写入卡夫卡主题
我有一个简单的结构化流媒体应用程序,它只从一个卡夫卡主题读取数据,然后写入另一个Apache spark 将Spark结构化流式输出写入卡夫卡主题,apache-spark,apache-kafka,spark-structured-streaming,Apache Spark,Apache Kafka,Spark Structured Streaming,我有一个简单的结构化流媒体应用程序,它只从一个卡夫卡主题读取数据,然后写入另一个 SparkConf conf=new SparkConf() .setMaster(“本地[*]”) .setAppName(“测试”); 火花会话火花=火花会话 .builder() .config(conf) .getOrCreate(); 数据集=spark .readStream() .格式(“卡夫卡”) .option(“kafka.bootstrap.servers”,“localhost:9092”)
SparkConf conf=new SparkConf()
.setMaster(“本地[*]”)
.setAppName(“测试”);
火花会话火花=火花会话
.builder()
.config(conf)
.getOrCreate();
数据集=spark
.readStream()
.格式(“卡夫卡”)
.option(“kafka.bootstrap.servers”,“localhost:9092”)
.期权(“认购”、“启动”)
.load();
StreamingQuery=数据集
.writeStream()
.格式(“卡夫卡”)
.option(“kafka.bootstrap.servers”,“localhost:9092”)
.选项(“检查点位置”、“检查点”)
.选项(“主题”、“结束”)
.start();
待终止查询(20000);
主题
start
上有两条消息需要处理。此代码毫无例外地运行,但是主题end
上不会出现任何消息。此示例有什么问题?问题在于消息已经在流中,并且起始偏移量没有设置为“最早”
Dataset=spark
.readStream()
.格式(“卡夫卡”)
.option(“kafka.bootstrap.servers”,“localhost:9092”)
.option(“订阅”,start.getTopicName())
.选项(“起始偏移量”、“最早”)
.load();