我正在使用 spring 集成,我有下一个案例:我正在读取一个带有 int-file:inbound-channel-adapter 的 XML 文件,我用 拆分文件em>int-xml:xpath-splitter,问题是我需要在拆分后移动文件。
我想要 int-xml:xpath-splitter 的所有功能加上移动文件,我应该实现一个扩展 XPathMessageSplitter 的自定义拆分器吗?还是有任何其他方法可以使用开箱即用的组件来做到这一点?
谢谢。
<int-xml:xpath-splitter id="salesTransSplitter"
input-channel="salesInputChannel"
output-channel="splitterOutChannel" order="1">
<int-xml:xpath-expression expression="/sales_transactions/trans"/>
</int-xml:xpath-splitter>
最佳答案
像这样的东西应该有用...
<int-file:inbound ... channel="foo" />
<int:publish-subscribe-channel id="foo" />
<int-xml:xpath-splitter input-channel="foo" ... order="1" />
<int-service-activator input-channel="foo" order="2"
expression="payload.renameTo(new java.io.File('/newDir/' + payload.name)" output-channel="nullChannel" />
如果您想测试重命名是否成功,请发送到 nullChannel
以外的其他 channel - bool 值 true 表示成功。
编辑
对此感到抱歉; order
应在每个消费端点上得到支持,我将打开一个 JIRA 问题。
order
不是绝对必要的;如果不存在 order
,将使用它们在配置中出现的顺序;我只是想把它说清楚。
有(至少)两个解决方法:
- 从 BOTH 消费者中删除
order
属性,他们将按照它们在 XML 中出现的顺序被调用。 将 XPath 拆分器配置为普通拆分器,它确实支持顺序...
<int:splitter id="salesTransSplitter" order="1" input-channel="salesInputChannel" output-channel="splitterOutChannel" order="1"> <bean class="org.springframework.integration.xml.splitter.XPathMessageSplitter"> <constructor-arg value="/sales_transactions/trans" /> </bean> </int-xml:xpath-splitter>
关于Spring Integration - 在 Xpath-splitter 之后移动文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34074777/