0
votes

I am working on mule flow where I need to read a properties file which will have a multiple organizations FTP endpoints. Whenever a flow starts, it should iterate over the property file and start consuming data from different FTP endpoints. Sample property file:

organizations:
    OrgA:
        FTPEndpoint: sftp://{orgAUser}:{password}@{hostA}:22/incoming/test
    OrgB:
        FTPEndpoint: sftp://{orgBUser}:{password}@{hostB}:22/incoming/test

I want to understand how to iterate over a yaml property file? Some code snippet would be appreciated. Also, I read in mulesoft document that you cannot put inbound endpoint in foreach loop. If this is the case then how can we achieve this?

Thanks & Regards, Vikas Gite

1

1 Answers

1
votes

i want to understand how to iterate over a yaml property file

reading config file (yaml):

<context:property-placeholder properties-ref="myConfig" />    
<spring:beans>
    <spring:bean id="myConfig" class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean">
        <spring:property name="resources" value="classpath:config.yaml"/>
    </spring:bean>
</spring:beans>

and here is a Java component which iterates over the entries:

public class ConfigExample implements Initialisable {

    private Properties props;

    @Override
    public void initialise() throws InitialisationException {
        props.entrySet().forEach(entry -> {
            // do what ever you want with configuration entries.
            // for example System.out.println :)

            System.out.println(entry.getKey() + ": " + entry.getValue());
        });
    }

    public Properties getProps() {
        return props;
    }

    public void setProps(Properties props) {
        this.props = props;
    }
}

inject the myConfig in ConfigExample:

<spring:beans>
   <spring:bean class="ConfigExample">
       <spring:property name="props" ref="myConfig" />
   </spring:bean>
</spring:beans>

Also, I read in mulesoft document that you cannot put inbound endpoint in foreach loop. If this is the case then how can we achieve this?

that is right, you wont be able to iterate over inbound endpoints, but you can create flows with inbound endpoints and start them based on your configuration. Here Faraz Masood describes how to do it.