首页 文章

如何使用jdbc-outbound-channel-adapter过滤Spring Integration流?

提问于
浏览
1

我有一个要求,我必须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相同 . 请指教 .

我绝对可以做的是写一个引用bean返回true或false的 <int:filter> . 但我只是想避免编写这个Java代码!

1 回答

  • 1

    保存 Headers 中的原始有效负载并稍后恢复...

    <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) .

    如果您愿意,可以将所有这些放在_2353615中 .

相关问题