2017-04-07 43 views
0

我正在使用mule流程,我需要讀取將具有多個組織FTP端點的屬性文件。每當流程開始時,它應該遍歷屬性文件並開始使用來自不同FTP端點的數據。 樣本屬性文件:mulesoft,通過屬性文件循環並啓動入站端點

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

我想了解如何遍歷一個YAML屬性文件?一些代碼片段將不勝感激。 另外,我在mulesoft文檔中讀到,您不能將入站端點放在foreach循環中。如果是這種情況,那我們該如何實現呢?

感謝&問候, 維卡斯飯店Gite

回答

1

我想了解如何遍歷一個YAML屬性文件

讀取配置文件(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> 

和這裏是一個Java組件,它遍歷這些條目:

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

注入myConfigConfigExample

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

另外,我認爲你不能把入站端點foreach循環mulesoft文件中讀取。如果是這種情況,那我們該如何實現呢?

這是正確的,你將無法遍歷入站端點,但您可以根據您的配置創建入站端點流和啓動它們。法拉茲馬蘇德介紹瞭如何做到這一點。