mule move file to another location dynamically from the db query

被刻印的时光 ゝ 提交于 2019-12-25 01:48:13

问题


I want to move files to location D:\target dynamically from the query select filepath from emp where status='y':

This is my table:

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

Following is my source code :

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

But it's not working.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/29372873/mule-move-file-to-another-location-dynamically-from-the-db-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!