What Does the clone parameter in the Enrich mediator mean?
In the context of the WSO2 Micro Integrator (MI) <enrich> mediator:
<source clone="false" type="body"/>
<target property="ORIGINAL-PAYLOAD" type="property"/>
</enrich>
clone="false" →
Ensures the payload is referenced directly instead of creating a
deep copy (duplication) of the message.Why Does This Matter?
In WSO2 MI, the message context (including the payload) is stored in memory as an OM (Object Model) structure, which is part of the AXIOM (AXis Object Model) framework.
- clone="false" → References the existing payload without copying data in memory.
- clone="true" → Creates a new copy of the payload (uses additional memory and CPU cycles).
Example to Illustrate the Difference
Payload Before Enrich Mediator
Incoming XML payload:Enrich Mediator with clone="false"
(Recommended for Performance)
- No new copy is created.
- The ORIGINAL-PAYLOAD property points to the same memory reference as the original payload.
- If the payload is modified later, the ORIGINAL-PAYLOAD will reflect those changes.
Enrich Mediator with clone="true" (Data Duplication)
- A new copy of the payload is created in memory.
- Changes made to the original payload later will not affect the copy stored in ORIGINAL-PAYLOAD.
Slower because it consumes more memory and CPU.
When to Use Each Option?
| Use Case | Recommended Option |
|---|---|
| Log the payload without modifying it | clone="false" |
| Backup the payload before modifying it | clone="true" |
| Capture large payloads in performance-critical flows | clone="false" |
| Ensure payload integrity for error handling | clone="true" |
Example Flow Using Both Options
Scenario: Capture the original payload for logging and modify the message later.Since clone="false" was used earlier, ORIGINAL-PAYLOAD is updated as well.
Value of ORIGINAL-PAYLOAD (and the modified payload):
Key Takeaways
- clone="false" — Best for performance; avoids unnecessary memory duplication but reflects changes made to the original payload.
- clone="true" — Creates a deep copy of the payload, ideal for protecting the original data from modifications.
For performance-critical scenarios or large payloads, clone="false" is generally preferred.