【问题标题】:inbound-channel-adapter local-directory & message入站通道适配器本地目录和消息
【发布时间】:2015-10-14 09:08:42
【问题描述】:

我们有 Web 应用程序并希望使用 ftp:inbound-channel-adapter 从 ftp 读取文件并创建消息并将其发送到通道

  1. local-directory 设置为 local-directory="#servletContext.getRealPath('')}/temp/inFtp" 它给出 生成的消息是 GenericMessage [payload={applicationDeployPath}\temp\inFtp\xyz.stagging.dat, headers={timestamp=1444812027516, id=9b5f1581-bfd2-6690-d4ea-e7398e8ecbd6}]

但是没有创建目录,我检查了我在这里有完全权限。 路径 [{applicationDeployPath}\temp\inFtp] 不表示可正确访问的目录。

  1. 在消息中,我想根据环境发送更多字段作为具有属性文件值的有效负载,我该怎么做?

    <int-ftp:inbound-channel-adapter id="ftpInboundAdaptor"
        channel="ftpInboundChannel"
        session-factory="ftpClientFactory"
        filename-pattern="*.stagging.dat"
        delete-remote-files="false"
        remote-directory="/stagging/"
        local-directory="#servletContext.getRealPath('')}/temp/inFtp"
        auto-create-local-directory="true">
        <int:poller  fixed-rate="1000"/>
    </int-ftp:inbound-channel-adapter>
    

提前致谢

【问题讨论】:

    标签: ftp spring-integration adaptor


    【解决方案1】:

    local-directory 仅在初始化时评估一次(并在必要时创建),而不是针对每条消息。

    我对上下文初始化感到惊讶;这个语法看起来很糟糕:

    local-directory="#servletContext.getRealPath('')}/temp/inFtp"
    

    如果你的意思是

    local-directory="#{servletContext.getRealPath('')}/temp/inFtp"
    

    只有当你有一些名为 servletContext 的 bean 时它才会起作用。

    如果你的意思是

    local-directory="#servletContext.getRealPath('')/temp/inFtp"
    

    您需要在评估上下文中使用变量 servletContext

    它给出的 Message 生成的是 GenericMessage [payload={applicationDeployPath}\temp\inFtp\xyz.stagging.dat, headers={timestamp=1444812027516, id=9b5f1581-bfd2-6690-d4ea-e7398e8ecbd6}]

    如果它实际上是在生成该消息,那么它一定是创建了该目录。

    不清楚你的意思

    我想发送更多字段作为有效负载

    有效载荷是File

    如果要将有效负载更改为包含文件和其他字段的其他内容,请使用转换器。

    【讨论】:

    • 感谢 Gary,为了在消息负载中添加额外信息,我将使用转换器。写问题的时候打错字了。正如您也提到的,真正的配置是local-directory="#{servletContext.getRealPath('')}/temp/inFtp"。并且正在创建文件夹,并且正在按预期复制文件,但是由于它是共享临时空间,因此被另一个进程清除了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多