Overview
Fetches data from Pricefx and writes it as a CSV file to an SFTP server. Uses batched mode for large datasets.
Prerequisites
Define the SFTP connection in connections/sftp-server.json (see Connection Examples > SFTP Connection Setup).
Filter: filters/export-filter.xml
<filters>
<filter id="exportFilter">
<and>
<criterion fieldName="attribute1" operator="equals" value="ACTIVE"/>
</and>
</filter>
</filters>
Route: routes/export-to-sftp.xml
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="exportPricesToSftp">
<from uri="scheduler://exportTrigger?delay={{export.interval.ms}}"/>
<to uri="pfx-api:fetch?objectType=PX&filter=exportFilter&batchedMode=true&batchSize=5000"/>
<split>
<simple>${body}</simple>
<to uri="pfx-api:fetchIterator"/>
<to uri="pfx-csv:marshal"/>
<to uri="pfx-sftp:upload?connection=sftpServer&fileName={{sftp.path}}/prices_${date:now:yyyyMMdd_HHmmss}.csv&fileExist=Append"/>
</split>
</route>
</routes>
Properties:
export.interval.ms=3600000
sftp.path=/incoming/prices
How It Works
-
scheduler://triggers the route periodically (every hour in this example) -
pfx-api:fetchwithbatchedMode=truereturns batch descriptors instead of data -
split+pfx-api:fetchIteratorfetches each batch — avoids loading all records into memory -
pfx-csv:marshalconverts each batch to CSV text -
pfx-sftp:uploadappends each batch to the same file on the SFTP server
Common Pitfalls
-
Use
batchedMode=truefor large exports to avoidOutOfMemoryError -
fileExist=Appendis needed when writing batches to the same file — without it, each batch overwrites the previous -
The timestamp in
fileNameensures a new file is created each run if you removefileExist=Append