Contact Us 1-800-596-4880

Migrating the Enricher to a Target Variable

Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule reached its End of Life on November 2, 2022, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

The Message Enricher and its functionality in Mule 3 is replaced by the target parameter in Mule 4. The Enricher provided a way to execute a group of message processors and redirect their output to a variable without side effects to the current message. In Mule 4, all non-void operations (for example, <flow-ref>, <http:request>, <ftp:write>, <db:select>, and so on) include target and targetValue parameters, which allow redirecting each operation’s output into a variable (such as myVar). Other components in a Mule flow can then access that data through a DataWeave selector (for example, vars.myVar).

Consider a message coming from an HTTP request, which we want to redirect to a third system, only that adding a state query param which is to be extracted using a secondary flow called stateLookup. Because you don’t want to lose the original payload or headers, you need to extract this value without affecting the original message. The Enricher calls out to the enrichment resource with the current message (containing the zip code), then enriches the current message with the result.

Mule 3 example
<flow name="orderProcessingFlow">
   <http:listener .../>
   <enricher target="#[variable:state]">
       <flow-ref name="stateLookup"/>
   </enricher>
  <http:request config-ref="config" path="state" method="POST">
    <http:request-builder>
        <http:query-param paramName="state" value="#[flowVars.state]" />
    </http:request-builder>
  </http:request>
</flow>

In Mule 4, you can simply use the target parameter in the <flow-ref> operation:

Mule 4 example
<flow name="orderProcessingFlow">
  <http:listener .../>
  <flow-ref name="stateLookup" target="state" />
  <http:request config-ref="config" path="state" method="POST">
    <http:query-params>
      #[{'state' : vars.state}]
    </http:query-params>
  </http:request>
</flow>

See Also