我正在使用WSO2 ESB 4.9,在代理中,transport.vfs.FileURI参数用于提供输入路径,该路径是SFTP服务器中需要处理文件的文件夹,但我需要配置多个来自同一代理中不同SFTP服务器的输入路径。有关如何实现这一目标的任何建议吗?
答案 0 :(得分:1)
您可以使用scheduled task来触发对代理的注入。此代理将使用file connector从两个(或更多)输入路径读取文件。您必须使用文件连接器的different operations手动调整文件(搜索,迭代找到的文件,读取,删除,移动等)。
每30秒从两个输入路径读取.txt文件的示例:
预定任务:
<?xml version="1.0" encoding="UTF-8"?>
<task name="Demo_TaskFileConnector_task" class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" xmlns="http://ws.apache.org/ns/synapse">
<!-- This task will inject a message to a proxy every 30 seconds -->
<trigger interval="30" />
<property name="injectTo" value="proxy" />
<property name="proxyName" value="Demo_TaskFileConnectorMultipleInput_pFromFileConnector" />
<property name="format" value="soap12" />
<property name="message">
<Trigger xmlns="">
<GetFiles />
</Trigger>
</property>
代理:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="Demo_TaskFileConnectorMultipleInput_pFromFileConnector" transports="jms" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property name="fileLocation1" value="sftp://UserName:Password@Host1/directory" />
<property name="fileLocation2" value="sftp://UserName:Password@Host2/directory" />
<!-- Read in *.txt files from fileLocation1 -->
<fileconnector.search>
<source>{$ctx:fileLocation1}</source>
<filePattern>.*[.](?i)txt$</filePattern>
<recursiveSearch>false</recursiveSearch>
</fileconnector.search>
<!-- Iterate the list of found files in fileLocation1 -->
<foreach xmlns:ns="http://org.wso2.esbconnectors.FileConnector" xmlns:ns2="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//ns:file">
<sequence>
<!-- Parse the file name of the found file to use it for reading in -->
<property name="fileName" expression="tokenize(//ns:file, '/')[last()]" />
<!-- Read in the content of the file -->
<fileconnector.read>
<source>{$ctx:fileLocation1}</source>
<filePattern>{$ctx:fileName}</filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
<!-- Go on with the mediation of the file. e.g. send to an endpoint -->
<!-- Here I simply log the message content -->
<log level="full" />
</sequence>
</foreach>
<!-- Read in *.txt files from fileLocation2 -->
<fileconnector.search>
<source>{$ctx:fileLocation2}</source>
<filePattern>.*[.](?i)txt$</filePattern>
<recursiveSearch>false</recursiveSearch>
</fileconnector.search>
<!-- Iterate the list of found files in fileLocation2 -->
<foreach xmlns:ns="http://org.wso2.esbconnectors.FileConnector" xmlns:ns2="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//ns:file">
<sequence>
<!-- Parse the file name of the found file to use it for reading in -->
<property name="fileName" expression="tokenize(//ns:file, '/')[last()]" />
<!-- Read in the content of the file -->
<fileconnector.read>
<source>{$ctx:fileLocation2}</source>
<filePattern>{$ctx:fileName}</filePattern>
<contentType>text/plain</contentType>
</fileconnector.read>
<!-- Go on with the mediation of the file. e.g. send to an endpoint -->
<!-- Here I simply log the message content -->
<log level="full" />
</sequence>
</foreach>
</inSequence>
</target>
</proxy>