我有一个 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"/>
传入文件由一项服务分割并生成一个列表报告内容.
然后服务链获取每个元素报告内容并对它们进行处理,从文件内容(如报告 ID、报告类型)中读取报告元数据,将报告内容字符串保存到相应目录中的文件中,并将报告元数据保存在数据库中。除了似乎有一个松散的末端之外,流程工作正常。
我得到以下异常。
org.springframework.integration.MessageDeliveryException:调度程序
没有订阅者
我不需要聚合拆分的元素。据我所知,在将元数据保存到数据库后,流程就完成了。
但是,我想在使用原始文件(我拆分为报告文件的主文件)后将其移动到其他目录。我怎样才能整合这个逻辑? File:outbound-channel 似乎是这样做的方法,但我不明白如何做。
有没有办法避免基于 readReportMetaData 操作中读取的某些元数据的 saveReportFileInSystem 和 saveReportMetaDataInDB 操作。
为了方便起见,我在下面给出了我的服务类的结构。
类:文件分割器
public List<ReportContent> splitFilesToReportContent(File file){
}
类:报告处理器
public ReportContent readReportMetaData(ReportContent reportContent) {
}
public ReportContent saveReportFileInFileSystem(ReportContent reportContent) {
}
public ReportContent saveReportMetaDataInDB(ReportContent reportContent) {
}
需要注意的一件事是我没有使用消息标题。我还没有觉得有必要使用,但我可以使用。我是 Spring 集成的新手,因此任何改进此流程的建议都会有所帮助。
1.我收到以下异常... org.springframework.integration.MessageDeliveryException
我想你已经错过了file:outbound-channel-adapter
定义在这里。
2. 但是,我想在使用原始文件(我拆分为报告文件的主文件)后将其移动到其他目录。我怎样才能整合这个逻辑?
正如所写14.3.4 文件出站通道适配器 http://docs.spring.io/spring-integration/reference/html/files.html#file-outbound-channel-adapter你应该使用delete-source-files
属性为outbound-channel-adapter
but(!)
...属性仅在入站消息具有文件有效负载或 FileHeaders.ORIGINAL_FILE 标头值包含源文件实例或表示原始文件路径的字符串时才有效。
所以,在你reportProcessorService
无论如何你应该处理原始消息。您不再有源文件作为有效负载。因此,只有一种选择是正确设置FileHeaders.ORIGINAL_FILE
标头值。
3.有没有办法避免基于readReportMetaData操作中读取的某些元数据进行saveReportFileInSystem和saveReportMetaDataInDB操作?
就在这里。之后使用readReportMetaData
在链 EIP 中负载类型路由器 http://docs.spring.io/spring-integration/reference/html/messaging-routing-chapter.html#router-implementations-payloadtyperouter(如果可能的话,因为它很简单)或配置(通用)路由器 http://docs.spring.io/spring-integration/reference/html/messaging-routing-chapter.html#router-namespace
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)