我有一个要求,我必须通过FTP从远程服务器读取XML文件,并将它们转储到本地目录中。之后,我必须使用传入负载中的值对数据库启动SQL查询,然后根据查询结果决定是否继续流。
<int-ftp:inbound-channel-adapter id="ftpInbound1"
channel="inboundFTPFileChannel" session-factory="ftpSessionFactory"
local-filter="compositeFilter" filename-pattern="*.xml"
preserve-timestamp="true" charset="UTF-8" remote-directory="${remote.request.cdr.circle.dir}"
remote-file-separator="/" local-directory="${local.request.dir}">
<int:poller fixed-rate="${ftp.file.poller.interval}"
time-unit="SECONDS" max-messages-per-poll="-1" />
</int-ftp:inbound-channel-adapter>
<int:filter input-channel="inboundFTPFileChannel"
output-channel="jdbcChannel" discard-channel="discardChannel"
expression="payload.isFile()" />
<int-jdbc:outbound-channel-adapter
channel="jdbcChannel" query="SELECT COUNT(1) FROM some_table WHERE some_col = some_value"
data-source="myDataSource" />
在这个阶段,如果查询返回非零输出,我希望继续流。否则,此消息的流应该结束。此外,如果流应该继续,那么下一个通道的输出应该与"jdbcChannel"上的Spring Integration Message相同。请提供建议。
我可以肯定地做的是编写一个<int:filter>
,它引用返回true或false的bean。但我只是想避免编写这种Java代码!
保存头中的原始有效负载,稍后恢复。。。
<int:header-enricher ...>
<int:header name="savedPayload" expression="payload" />
</int:header-enricher>
<int:jdbc-outbound-gateway... />
<int:filter ... expression="payload > 0" />
<int:transformer ... expression="headers['savedPayload']" />
...
请注意,您需要使用网关,而不是通道适配器(JDBC(。
如果你愿意,你可以把所有这些放在<chain/>
中。