Event-Driven Examples
Examples of event-driven integrations — reacting to Pricefx events like data loads, calculations, and approvals.
Three approaches are supported:
|
Approach |
When to Use |
|---|---|
|
Approach 1: Properties-based (recommended) |
Most integrations — minimal boilerplate, handles caching/retry automatically |
|
Approach 2: Direct pfx-event:fetch |
Multiple event types with shared pre-processing, custom polling control |
|
Approach 3: Send Custom Events |
Trigger other integrations by publishing a custom event from a route |
See Events for configuration properties and setup.
Approach 1: Properties-Based (Recommended)
Configure event-to-route mappings in config/application.properties. IM creates the fetch and file-consumer routes automatically — you only write the handler route.
React to Data Load Completion
Truncate and refresh a derived data feed whenever a DMDS flush completes.
config/application.properties:
integration.events.enabled=true
integration.events.event-to-route-mapping.PADATALOAD_COMPLETED=direct:eventPADataLoadCompleted
routes/eventPADataLoadCompleted.xml:
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventPADataLoadCompleted">
<from uri="direct:eventPADataLoadCompleted"/>
<setHeader name="targetName">
<simple>${body[data][0][targetName]}</simple>
</setHeader>
<choice>
<when>
<simple>${headers.targetName} == 'DMDS.Product'</simple>
<to uri="pfx-api:truncate?targetName=DMF.Product"/>
<to uri="direct:loadProductData"/>
</when>
</choice>
</route>
<route id="loadProductData">
<from uri="direct:loadProductData"/>
<to uri="pfx-api:fetch?objectType=DS&dsUniqueName=DMDS.Product&filter=allProducts"/>
<split>
<simple>${body}</simple>
<to uri="pfx-api:loaddata?objectType=DM&dsUniqueName=DMF.Product&mapper=productMapper"/>
</split>
<onCompletion onCompleteOnly="true">
<to uri="pfx-api:flush?dataFeedName=DMF.Product&dataSourceName=DMDS.Product"/>
</onCompletion>
</route>
</routes>
React to Calculation Completion
Export CFS calculation results to a file after each completed calculation.
config/application.properties:
integration.events.enabled=true
integration.events.event-to-route-mapping.CALCULATION_COMPLETED_CFS=direct:eventCFSCompleted
routes/eventCFSCompleted.xml:
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventCFSCompleted">
<from uri="direct:eventCFSCompleted"/>
<setHeader name="cfsName">
<simple>${body[data][0][targetName]}</simple>
</setHeader>
<log message="CFS calculation completed: ${headers.cfsName}"/>
<to uri="pfx-api:fetch?objectType=CFS&filter=allResults"/>
<to uri="pfx-csv:marshal"/>
<setHeader name="CamelFileName">
<simple>cfs-export-${date:now:yyyyMMdd-HHmmss}.csv</simple>
</setHeader>
<to uri="file:{{outbound.path}}"/>
</route>
</routes>
React to Price Grid Item Approval
integration.events.enabled=true
integration.events.event-to-route-mapping.ITEM_APPROVED_PGI=direct:eventItemApproved
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventItemApproved">
<from uri="direct:eventItemApproved"/>
<log message="Item approved: ${body[data][0][id]}"/>
<to uri="pfx-api:fetch?objectType=PGI&filter=approvedItem"/>
<to uri="pfx-rest:post?connection=erpConnection&path=/prices/update"/>
</route>
</routes>
React to a Custom Event
Custom events use CUSTOM. prefix in the property key.
integration.events.enabled=true
integration.events.event-to-route-mapping.CUSTOM.PRICE_EXPORT_REQUESTED=direct:eventPriceExportRequested
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventPriceExportRequested">
<from uri="direct:eventPriceExportRequested"/>
<setHeader name="exportFormat">
<simple>${body[data][0][format]}</simple>
</setHeader>
<to uri="direct:runExport"/>
</route>
</routes>
Approach 2: Direct pfx-event:fetch
Use pfx-event:fetch directly as the route <from> consumer.
Custom Event Routing (Multiple Event Types)
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventFetch">
<from uri="pfx-event:fetch
?eventTypes=PADATALOAD_COMPLETED,CALCULATION_COMPLETED_CFS,ITEM_APPROVED_PGI
&maxEvents=500
&delay=10000
&initialDelay=5000"/>
<setHeader name="eventType">
<simple>${body[eventType]}</simple>
</setHeader>
<choice>
<when>
<simple>${headers.eventType} == 'PADATALOAD_COMPLETED'</simple>
<to uri="direct:handlePADataLoad"/>
</when>
<when>
<simple>${headers.eventType} == 'CALCULATION_COMPLETED_CFS'</simple>
<to uri="direct:handleCFSCalc"/>
</when>
<when>
<simple>${headers.eventType} == 'ITEM_APPROVED_PGI'</simple>
<to uri="direct:handleItemApproval"/>
</when>
</choice>
</route>
<route id="handlePADataLoad">
<from uri="direct:handlePADataLoad"/>
<log message="PA data load completed: ${body[data][0][targetName]}"/>
<to uri="pfx-api:truncate?targetName=DMF.Product"/>
</route>
<route id="handleCFSCalc">
<from uri="direct:handleCFSCalc"/>
<to uri="pfx-api:fetch?objectType=CFS&filter=allResults"/>
<to uri="pfx-csv:marshal"/>
<to uri="file:{{outbound.path}}?fileName=cfs-results.csv"/>
</route>
<route id="handleItemApproval">
<from uri="direct:handleItemApproval"/>
<to uri="pfx-rest:post?connection=erpConnection&path=/prices/update"/>
</route>
</routes>
Poll with Different Intervals per Event Type
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="pollDataLoadEvents">
<from uri="pfx-event:fetch?eventTypes=PADATALOAD_COMPLETED&delay=30000"/>
<to uri="direct:handlePADataLoad"/>
</route>
<route id="pollApprovalEvents">
<from uri="pfx-event:fetch?eventTypes=ITEM_APPROVED_PGI&delay=300000"/>
<to uri="direct:handleItemApproval"/>
</route>
</routes>
Approach 3: Send Custom Events
Use pfx-event:sendCustom to publish a custom event from within a route.
Publish a Custom Event After Load
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="loadAndNotify">
<from uri="file:{{inbound.path}}"/>
<to uri="pfx-csv:unmarshal?header=sku,label,price&skipHeaderRecord=true"/>
<split>
<simple>${body}</simple>
<aggregate strategyRef="aggregateToList" completionSize="500">
<correlationExpression><constant>true</constant></correlationExpression>
<to uri="pfx-api:loaddata?objectType=P&mapper=productMapper"/>
</aggregate>
</split>
<onCompletion onCompleteOnly="true">
<setBody><constant>{}</constant></setBody>
<to uri="pfx-event:sendCustom?eventType=PRICE_EXPORT_REQUESTED"/>
</onCompletion>
</route>
</routes>
Chain Integrations via Custom Events
Integration A — sends the event:
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="integrationA">
<from uri="timer://trigger?repeatCount=1"/>
<to uri="pfx-api:fetch?objectType=P&filter=changedProducts"/>
<setBody><constant>{}</constant></setBody>
<to uri="pfx-event:sendCustom?eventType=PRODUCT_SYNC_DONE"/>
</route>
</routes>
Integration B — reacts (Approach 1):
integration.events.enabled=true
integration.events.event-to-route-mapping.CUSTOM.PRODUCT_SYNC_DONE=direct:eventProductSyncDone
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventProductSyncDone">
<from uri="direct:eventProductSyncDone"/>
<to uri="pfx-api:calculate?objectType=CFS&targetName=PriceMatrix"/>
</route>
</routes>
See Also
-
Events — Configuration, properties, stuck event monitoring
-
pfx-event Component — pfx-event:fetch and pfx-event:sendCustom parameter reference