EIPinCPI – Idempotent Receiver
This week, we’ll study a pattern known as Idempotent Receiver.
When do I use this pattern?
An Idempotent function is a function that returns itself when applied on itself. In messaging, an Idempotent Receiver will be able to process a duplicate message to result in the same end state of the system as if the message was processed once.
Idempotent Receiver in CPI
In CPI, I’ll demonstrate the Idempotent Receiver using an example of customer sync flow. The customer is updated in the master system and all the other systems should get the update.
This payload is set in ‘Set Body’ content modifier:
<?xml version="1.0" encoding="UTF-8"?> <UpdateMultipleObjectsOperationsSchema> <Account> <Operation>UPDATE</Operation> <ObjectType>Account</ObjectType> <ExternalID>SAP_Customer_Id__c</ExternalID> <Condition>Last_Modified_Date__c <= 2020-09-27T16:53:27.000Z</Condition> <TransactionLevel>REQUIRED</TransactionLevel> <sObjects> <sObject> <SAP_Customer_Id__c>0051234567</SAP_Customer_Id__c> <Name>SAP</Name> <Last_Modified_Date__c>2020-09-27T16:53:27.000Z</Last_Modified_Date__c> </sObject> </sObjects> </Account> </UpdateMultipleObjectsOperationsSchema>
In this example, the Idempotence is achieved using the message itself. The field Last_Modified_Date__c is set to a date and time when the customer was updated in the master system and the WHERE clause or the Condition field checks if the last modified date in the target system is in the past before actually performing the update.
If ECC is master and IDocs are being used to communicate change, then the fields CREDAT (created date) and CRETIM (created time) can be used to populate Last_Modified_Date__c. So, even if the same IDoc is sent twice because ECC did not receive an acknowledgement, the target system does not get updated unnecessarily.
EIPinCPI Rating – N/A
The EIPinCPI rating is not applicable for this pattern because the pattern describes how a receiver could be designed instead of the middleware system.
Idempotent Receiver is useful to prevent out of order or duplicate processing of the messages. In CPI, the Idempotence depends on the message itself and the receiver.
- Idempotent Receiver Pattern in Enterprise Integration Patterns
- CPI Components
Hope this helps,