【发布时间】:2016-03-03 14:37:21
【问题描述】:
我有一个如下的 Spring 集成流程。
<int-file:inbound-channel-adapter id="filesIn"
directory="file:${incomingDir}"
filename-pattern="*.txt"
prevent-duplicates="true">
<int:poller id="poller" fixed-delay="5000"/>
</int-file:inbound-channel-adapter>
<int:splitter input-channel="filesIn"
ref="filesSplitterService"
method="splitFilesToReportContent"
output-channel="reportProcessIn"
/>
<int:channel id="reportProcessIn"/>
<int:chain input-channel="reportProcessIn" output-channel="reportProcessOut">
<int:service-activator ref="reportProcessorService" method="readReportMetaData" />
<int:service-activator ref="reportProcessorService" method="saveReportFileInFileSystem" />
<int:service-activator ref="reportProcessorService" method="saveReportMetaDataInDB" />
</int:chain>
<int:channel id="reportProcessOut"/>
<bean id="filesSplitterService" class="com.app.integration.FilesSplitter"/>
<bean id="reportProcessorService" class="com.app.reporting.integration.ReportProcessor"/>
传入的文件被一个服务分割并形成一个ReportContent列表。
然后服务链获取 ReportContent 的每个元素并处理它们以从文件内容中读取_report_meta_data(如报告ID,报告类型),将报告内容字符串保存到相应目录中的文件中,并将报表元数据保存在数据库中。流程运行良好,但似乎有一个松散的结局。
我得到以下异常。
org.springframework.integration.MessageDeliveryException: Dispatcher 没有订阅者
我不需要聚合拆分的元素。就我而言,在将元数据保存在数据库中之后,流程就完成了。
但是,我想在使用原始文件(我拆分为报告文件的主文件)后将其移动到其他目录。我怎样才能融入这种逻辑? File:outbound-channel 似乎是这样做的方式,但我不明白如何。
有没有办法避免基于 readReportMetaData 操作中读取的一些元数据的 saveReportFileInSystem 和 saveReportMetaDataInDB 操作。
为方便起见,我在下面给出了我的服务类的结构。
类:FileSplitter
public List<ReportContent> splitFilesToReportContent(File file){
}
类:报告处理器
public ReportContent readReportMetaData(ReportContent reportContent) {
}
public ReportContent saveReportFileInFileSystem(ReportContent reportContent) {
}
public ReportContent saveReportMetaDataInDB(ReportContent reportContent) {
}
需要注意的一点是,我没有使用邮件标头。我还没有觉得有必要使用,但我可以使用。我是 Spring 集成的新手,所以任何改进此流程的建议都会有所帮助。
【问题讨论】:
标签: java spring file integration spring-integration