Examples of event-driven integrations — reacting to Pricefx events like data loads, calculations, and approvals.
Three approaches are supported:
|
Approach |
When to Use |
|---|---|
|
Most integrations — minimal boilerplate, handles caching/retry automatically |
|
|
Multiple event types with shared pre-processing, custom polling control |
|
|
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
Trigger a downstream push when a price grid item is approved.
config/application.properties:
integration.events.enabled=true
integration.events.event-to-route-mapping.ITEM_APPROVED_PGI=direct:eventItemApproved
routes/eventItemApproved.xml:
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventItemApproved">
<from uri="direct:eventItemApproved"/>
<setHeader name="itemId">
<simple>${body[data][0][id]}</simple>
</setHeader>
<log message="Item approved: ${headers.itemId}"/>
<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.
config/application.properties:
integration.events.enabled=true
integration.events.event-to-route-mapping.CUSTOM.PRICE_EXPORT_REQUESTED=direct:eventPriceExportRequested
routes/eventPriceExportRequested.xml:
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="eventPriceExportRequested">
<from uri="direct:eventPriceExportRequested"/>
<log message="Custom event received: ${body[eventType]}"/>
<!-- body[data] contains the payload sent with pfx-event:sendCustom -->
<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. Useful when you need to handle multiple event types in a single route or need fine-grained control over polling.
Custom Event Routing (Multiple Event Types)
Handle multiple event types in one route with shared pre-processing.
routes/eventFetch.xml:
<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"/>
<!-- shared pre-processing for all event types -->
<setHeader name="eventType">
<simple>${body[eventType]}</simple>
</setHeader>
<log message="Event received: ${headers.eventType}"/>
<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"/>
<to uri="direct:loadProductData"/>
</route>
<route id="handleCFSCalc">
<from uri="direct:handleCFSCalc"/>
<log message="CFS calculation done: ${body[data][0][targetName]}"/>
<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"/>
<log message="Item approved: ${body[data][0][id]}"/>
<to uri="pfx-rest:post?connection=erpConnection&path=/prices/update"/>
</route>
</routes>
Poll with Different Intervals per Event Type
When two event types need different polling frequencies, use two separate fetch routes.
<routes xmlns="http://camel.apache.org/schema/spring">
<!-- Poll for data load events every 30 seconds -->
<route id="pollDataLoadEvents">
<from uri="pfx-event:fetch?eventTypes=PADATALOAD_COMPLETED&delay=30000"/>
<to uri="direct:handlePADataLoad"/>
</route>
<!-- Poll for approval events every 5 minutes -->
<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. This allows one integration to trigger another asynchronously.
Publish a Custom Event
After loading data, publish a custom event to notify downstream integrations.
<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">
<!-- publish custom event after successful load -->
<setBody>
<simple>{"format": "csv", "count": "${exchangeProperty.CamelSplitSize}"}</simple>
</setBody>
<to uri="pfx-event:sendCustom?eventType=PRICE_EXPORT_REQUESTED"/>
</onCompletion>
</route>
</routes>
Chain Integrations via Custom Events
Integration A loads data and sends a custom event. Integration B listens and reacts.
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"/>
<!-- ... process data ... -->
<setBody><constant>{}</constant></setBody>
<to uri="pfx-event:sendCustom?eventType=PRODUCT_SYNC_DONE"/>
</route>
</routes>
Integration B — reacts to the event (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"/>
<log message="Product sync done — starting price calculation"/>
<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
-
Code Samples — Full working integration examples