Spring集成:逐行处理文件,持久化读取状态

huangapple go评论74阅读模式
英文:

Spring integration: process files line by line persisting read state

问题

我想使用Spring Integration文件逐行处理文件,似乎可以使用FileReadingMessageSourceFileSplitter来实现。

然而,当Spring Integration应用程序在处理文件时崩溃或重新启动时,我不希望行重新被处理(至少不要太多),也不希望丢失行。

在Spring Integration中,是否有一种方法可以保持文件的读取状态,以便在上次中断的地方重新启动处理?是否有人有这种场景的示例?

英文:

I want to process files line by line using Spring integration file, which seems to be possible using FileReadingMessageSource and FileSplitter.

However, when the Spring integration application crashes or is restarted while processing a file, I do not want lines to get re-processed (at least not too many) or to get lost.

Is there a way to keep the read state of a file in Spring integration, so that processing is restarted where it left off? Does anyone has an example of such a scenario?

答案1

得分: 1

FileSplitter中无法保持读取状态,但我可以建议您查看幂等接收器模式。因此,处理来自文件的行的端点可以跳过已处理过的行。

在文档中查看更多信息:https://docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/messaging-endpoints.html#idempotent-receiver

英文:

There is no way to keep a read state in the FileSplitter, however I can suggest you to take a look into the Idempotent Receiver pattern. So, an endpoint which processes the line from the file could skip those already processed.

See more info in the Docs:https://docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/messaging-endpoints.html#idempotent-receiver

huangapple
  • 本文由 发表于 2020年4月5日 16:44:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/61040057.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定