Resources
Static resources — templates, reference data, lookup files.
|
Attribute |
Details |
|---|---|
|
Purpose |
Store any static files needed by routes (Velocity templates, reference CSVs, lookup data, etc.) |
|
Format |
Any format — CSV, JSON, XML, Velocity templates, text files |
|
Naming |
By purpose: |
|
Loaded by |
Not auto-loaded. Referenced explicitly in routes. |
How to Use Resources in Routes
Resources are accessed via the pfx-resources component or standard Camel file: URIs.
Read a CSV lookup file
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="loadLookupData">
<from uri="timer://loadLookup?repeatCount=1"/>
<to uri="pfx-resources:read?fileName=country-codes.csv"/>
<to uri="pfx-csv:unmarshal?header=code,name&skipHeaderRecord=true"/>
<log message="Loaded ${body.size()} country codes"/>
</route>
</routes>
Use a Velocity template for error emails
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="sendErrorReport">
<from uri="direct:sendErrorReport"/>
<to uri="velocity:resources/email-template.vm"/>
<to uri="pfx-smtp:send?to={{alert.email}}"/>
</route>
</routes>
Read a JSON configuration file
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="readConfig">
<from uri="timer://readConfig?repeatCount=1"/>
<to uri="pfx-resources:read?fileName=mapping-config.json"/>
<unmarshal>
<json library="Jackson"/>
</unmarshal>
<log message="Config loaded: ${body}"/>
</route>
</routes>
Common Pitfalls
-
Not auto-loaded — Unlike routes, mappers, and filters, resource files are not automatically loaded at startup. You must explicitly read them in your route.
-
Path is relative — The file name in
pfx-resources:readis relative to theresources/directory. Do not use absolute paths. -
File changes require restart — Resource files are read at route execution time, but the file system is synced from Git by PlatformManager. Changes may require a restart to be picked up.