trilawney
trilawney

Reputation: 1792

How to configure multiple inputs in WSO2 ESB?

I am using WSO2 ESB 4.9 and in the proxy , the transport.vfs.FileURI parameter is used to provide the input path which is a folder in a SFTP server from which the files needs to be processed but i need to configure multiple input paths from different SFTP server in the same proxy. Any suggestions on how to achieve this?

Upvotes: 0

Views: 377

Answers (1)

sterae
sterae

Reputation: 11

You can use a scheduled task which triggers an injection to a proxy. This proxy will read in the files from two (or more) input paths using the file connector. You have to do the steps to mediate the files manually (search, iterate the found files, read, delete, move etc.) using the different operations of the file connector.

Example of reading in .txt files from two input paths every 30 seconds:

Scheduled Task:

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

Proxy:

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

Upvotes: 1

Related Questions