2017-10-29 13 views
1

VFS를 통해 읽고있는 CSV 파일이 있습니다. 파일을 읽은 후 Smoke를 사용하여 CSV 데이터를 XML로 변환 한 다음 다른 프록시로 보냅니다. 기본적으로 smooks는 전체 메시지를 하나의 xml 페이로드로 변환합니다.Smooks를 사용하여 WSO2 ESB 5.0에서 CSV 파일을 한 줄씩 읽습니다.

문제 :

기본 방법은 작은 파일에 대한 괜찮지 만, 내가 처리하는 데 매우 큰 파일을 가지고 내가 라인으로 파일 라인을 읽고 그 다음에 메시지를 보낼 수 원하는 구성 요소.

프록시 구성 :

<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="ParseTestCSV1" 
     startOnLoad="true" 
     statistics="disable" 
     trace="disable" 
     transports="vfs"> 
    <target> 
     <inSequence> 
     <log level="full" separator="*********Parsing Prroxy Started*****"/> 
     <smooks config-key="gov:/repository/csv/smooks-config.xml"> 
      <input type="text"/> 
      <output type="xml"/> 
     </smooks> 
     <log level="full" separator="********After Smooks*******"/> 
     <property name="OUT_ONLY" value="true"/> 
     <property action="remove" name="ClientApiNonBlocking" scope="axis2"/> 
     <call/> 
     <log level="full" separator="*******Message Sent*********"/> 
     </inSequence> 
     <outSequence/> 
     <faultSequence/> 
    </target> 
    <parameter name="transport.PollInterval">60</parameter> 
    <parameter name="transport.vfs.FileURI">vfs:file://C:\WSO2EnterpriseIntegrator\file\In</parameter> 
    <parameter name="transport.vfs.ContentType">text/plain</parameter> 
    <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter> 
    <parameter name="transport.vfs.MoveAfterFailure">vfs:file://C:\WSO2EnterpriseIntegrator\file\Fail</parameter> 
    <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter> 
    <parameter name="transport.vfs.FileNamePattern">convert.*.csv</parameter> 
    <parameter name="transport.vfs.MoveAfterProcess">vfs:file://C:\WSO2EnterpriseIntegrator\file\Out</parameter> 
    <description/> 
</proxy> 

Smooks 구성 파일 : 내 Smook의 구성 파일을 변환 할 수 있습니까

<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd"> 

     <resource-config selector="org.xml.sax.driver"> 

      <resource>org.milyn.csv.CSVReader</resource> 

      <param name="fields">$ignore$,firstname,lastname,age,street,address,statecode,postalcode,amount,code,date</param> 

      <param name="rootElementName">record</param> 

      <param name="recordElementName">csvRecord</param> 

     </resource-config> 

    </smooks-resource-list> 

한 줄을 읽은 다음 앞으로 보낼 수 있습니다. 모든 통찰력은 인정 될 것이다.

답변

1

XML의 각 주문에 대해 거대한 XML을 jms 메시지로 분할해야하는 비슷한 경우가있었습니다. freemaker 템플릿을 사용하여이 작업을 수행 할 수 있습니다.

기본적으로 freemarker 템플릿을 정의하고 라우터에 바인딩합니다.

예 :

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
~ Copyright (c) 2005-2010, WSO2 Inc. (http://wso2.com) All Rights Reserved. 
~ 
~ WSO2 Inc. licenses this file to you under the Apache License, 
~ Version 2.0 (the "License"); you may not use this file except 
~ in compliance with the License. 
~ You may obtain a copy of the License at 
~ 
~ http://www.apache.org/licenses/LICENSE-2.0 
~ 
~ Unless required by applicable law or agreed to in writing, 
~ software distributed under the License is distributed on an 
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
~ KIND, either express or implied. See the License for the 
~ specific language governing permissions and limitations 
~ under the License. 
--> 
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" 
         xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.3.xsd" 
         xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" 
         xmlns:file="http://www.milyn.org/xsd/smooks/file-routing-1.1.xsd" 
         xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd" 
         xmlns:jms="http://www.milyn.org/xsd/smooks/jms-routing-1.2.xsd"> 


       <core:namespaces> 
     <core:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/> 
     </core:namespaces> 

    <core:filterSettings type="SAX" /> 
    <jb:bean beanId="recordsAsXml" class="java.util.Hashtable" createOnElement="records"> 
    <jb:value data="records/Id" decoder="String" property="Id"></jb:value> 
    <jb:value data="records/Account_ID__c" decoder="String" property="accountID"></jb:value> 
    <!-- ...--> 
</jb:bean> 

    <ftl:freemarker applyOnElement="records"> 
     <!--<ftl:template>/repository/resources/smooks/record_as_xml.ftl</ftl:template>--> 
     <ftl:template><!--<order> 
     <id>${recordsAsXml.Id}</id> 
     <accountId>${recordsAsXml.accountID}</accountId> 
     <!-- ...--> 
    </order>--> 
     </ftl:template> 
     <ftl:use> 
      <ftl:bindTo id="recordAsXmlOutput"/> 
     </ftl:use> 
    </ftl:freemarker> 


    <jms:router routeOnElement="records" beanId="recordAsXmlOutput" destination="MyJMSQueue"> 
     <jms:message> 
     </jms:message> 
     <jms:jndi properties="/repository/resources/smooks/activemq.sr.jndi.properties" /> 
     <jms:highWaterMark mark="-1"/> 
    </jms:router> 
</smooks-resource-list> 

다음 문서도 도움이 될 수 있습니다.

Message processing with smooks