从数据库查询将文件动态地移动到另一个位置 [英] mule move file to another location dynamically from the db query

查看:101
本文介绍了从数据库查询将文件动态地移动到另一个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从查询select filepath from emp where status='y':

这是我的桌子:

emp_Name    File Path      File Name    Status
ABC         D:\emp           abc.txt     y
xyz         D:\emp           xyz.txt     y
bcs         D:\emp           bcs.txt     n

以下是我的源代码:

<flow name="testdbFlow1">
    <http:listener config-ref="HTTP_Listener_Configuration"
        path="/" doc:name="HTTP" />
    <jdbc-ee:outbound-endpoint queryKey="allEmps"
        queryTimeout="-1" connector-ref="JDBCConnector" exchange-pattern="request-response"
        doc:name="Database" />

    <foreach doc:name="Foreach">
        <choice doc:name="Choice">
            <when expression="#[payload.status == 'Y']">
                <processor-chain doc:name="Processor Chain">
                    <set-variable variableName="filePath" value="#[payload.filepath]"
                        doc:name="Variable" />
                    <set-variable variableName="filename" value="#[payload.filename]"
                        doc:name="Variable" />

                    <logger message="#[filePath]" level="INFO"
                        doc:name="Logger" />
                    <logger message="#[filename]"
                        level="INFO" doc:name="Logger" />

                    <file:inbound-endpoint path="#[filePath]" name="input" doc:name="File" 
                        pollingFrequency="12000" responseTimeout="10000"> <file:filename-wildcard-filter 
                        pattern="#[filename]" /> </file:inbound-endpoint>

                    <file:outbound-endpoint name="output" path="D:\target" doc:name="File"/>

                </processor-chain>
            </when>
            <otherwise>
                <processor-chain doc:name="Processor Chain">
                    <set-variable variableName="filePath" value="#[payload.filepath]"
                        doc:name="Variable" />
                    <set-variable variableName="filename" value="#[payload.filename]"
                        doc:name="Variable" />

                    <logger message="#[filePath]" level="INFO"
                        doc:name="Logger" />
                    <logger message="#[filename]"
                        level="INFO" doc:name="Logger" />

                </processor-chain>
            </otherwise>
        </choice>
    </foreach>

</flow>

但是它不起作用.

推荐答案

入站在流程中间开箱即用.我建议使用Groovy解决方案更简单,因为您完全知道需要使用的文件.

Inbound doesn't work out of the box in the middle of the flow. I would suggest a simpler solution using Groovy because you know exactly the file you need to consume.

不是使用file:inbound而是手动创建输入流:

Instead of using file:inbound create a input stream manually:

<set-payload value="#[groovy: new java.io.FileInputStream(new java.io.File(filename))]"/>

使用后,您将不得不使用另一个常规脚本删除文件.

You will have to delete the file with another groovy script after consumed.

这篇关于从数据库查询将文件动态地移动到另一个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆