我尝试解压缩文件并单独处理具有特定Xpath值的xml文件。下面是Spring DSL。
<camel:route id="unzip-file" startupOrder="400">
<from uri="file:{{download.folder}}?move={{download.archive}}&consumer.delay=10000"/>
<unmarshal ref="zipFileDataFormat"/>
<split streaming="true">
<simple>${body}</simple>
<to uri="log:org.apache.camel?level=INFO&showAll=true&multiline=true"/>
<to uri="file:{{extract.folder}}"/>
</split>
</camel:route>
<camel:route id="process-extracted-files" startupOrder="300">
<from uri="file://{{extract.folder}}?noop=true&consumer.delay=10000&delete=false"/>
<choice>
<when>
<simple>${file:ext} regex '(?i)(xml)'</simple>
<to uri="direct:process-xml-file"/>
</when>
<otherwise>
<log message="ignoring file ${file:name}, not XML"/>
</otherwise>
</choice>
</camel:route>
<camel:route id="process-xml-file" startupOrder="200">
<from uri="direct:process-extracted-files"/>
<log message="processing file ${file:name}" />
<choice>
<when>
<xpath>/invoices/@region='region1'</xpath>
<split>
<xpath>/invoices/invoice</xpath>
<log message="${body}"/>
</split>
</when>
<otherwise>
<log message="ignoring file ${file:name}, not 'region1'"/>
</otherwise>
</choice>
</camel:route>
我在日志中收到以下错误,不知道我错过了什么。
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[process-extracted-] [process-extracted-] [file://C:/Temp/invoices/extract?consumer.delay=10000&delete=false&noop=true ] [ 353]
[process-extracted-] [choice1 ] [when[simple{${file:ext} regex '(?i)(xml)'}]choice[] ] [ 354]
[process-extracted-] [to6 ] [direct:process-xml-file ] [ 5]
Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
Id ID-crm.bigcorp.co.za-51788-1385461098541-0-4
ExchangePattern InOnly
Headers {breadcrumbId=ID-crm.bigcorp.co.za-51788-1385461098541-0-3, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\Temp\invoices\extract\INVOICES_V2_DAILY_DELTA_20131105.xMl, CamelFileLastModified=1385450517644, CamelFileLength=205502, CamelFileName=INVOICES_V2_DAILY_DELTA_20131105.xMl, CamelFileNameConsumed=INVOICES_V2_DAILY_DELTA_20131105.xMl, CamelFileNameOnly=INVOICES_V2_DAILY_DELTA_20131105.xMl, CamelFileParent=C:\Temp\invoices\extract, CamelFilePath=C:\Temp\invoices\extract\INVOICES_V2_DAILY_DELTA_20131105.xMl, CamelFileRelativePath=INVOICES_V2_DAILY_DELTA_20131105.xMl, CamelRedelivered=false, CamelRedeliveryCounter=0}
BodyType org.apache.camel.component.file.GenericFile
Body [Body is file based: GenericFile[C:\Temp\invoices\extract\INVOICES_V2_DAILY_DELTA_20131105.xMl]]
]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://process-xml-file]. Exchange[INVOICES_V2_DAILY_DELTA_20131105.xMl]
答案 0 :(得分:1)
将子路由定义的URI更改为 direct:process-xml-file (与调用相同)
<from uri="direct:process-xml-file"/>