KafkaStream逻辑删除消息插入方法

时间:2018-08-20 10:29:05

标签: apache-kafka-streams spring-cloud-stream

我有一个文档流,它经过多个处理步骤。这些步骤是并行完成的。每个步骤完成后,将向stage completion主题发送一条消息。完成所有步骤后,跟踪器会向文档processing complete的{​​{1}}主题发送消息。

我在跟踪器中使用kafka流(顶部有春季云流)来实现上述功能。

以下是示例代码。

Id

发布完成消息后,需要清理该文档 @StreamListener @SendTo("processingComplete") public KStream<String, String> onCompletion(@Input("stageCompletion") KStream<String, String> stageCompletionStream) { return stageCompletionStream .filter(this::checkValidity) .groupByKey(Serialized.with(Serdes.String(), Serdes.String())) .reduce(this::aggregateStageCompletion, Materialized.as("stage_completion_store")) .toStream() .filter((ignored, message) -> checkCompletion(message)) .map(this::publishCompletion); } 的状态存储-stage_completion_store(默认情况下恰好是rock db)。

建议的方法是插入一个墓碑消息;为此,我还实现了另一个流来读取Id主题并将其与processing complete流合并。

以下是使用此方法的代码。

stage completion

当消息是处理完成消息时, @StreamListener @SendTo("processingComplete") public KStream<String, String> onCompletion(@Input("stageCompletion") KStream<String, String> stageCompletionStream,@Input("processingCompleteFeed") KStream<String, String> processingCompletionStream){ return processingCompletionStream.merge(stageCompletionStream) .filter(this::checkValidity) .groupByKey(Serialized.with(Serdes.String(),Serdes.String())) .reduce(this::aggregateStageCompletion, Materialized.as("stage_completion_store")) .toStream() .filter((ignored,message)->checkCompletion(message)) .map(this::publishCompletion); } 插入墓碑(返回aggregateStageCompletion)。

这是否是一种好方法-读取流只是为了标记墓碑?还是有更好的方法来达到相同的目的?

0 个答案:

没有答案
相关问题