Message Enricher Component in Mulesoft


In this walk through, we will see how to use message enricher component in mulesoft. This component allows to maintain the original payload which was received in the message flow.

Here is simple mule flow, which receives a booking request from the client and this does the booking of service requested and echos back the response to the client.
Run the mule application and test the flow. As you can see, we got the booking response.
Now lets try to archive original payload by adding a Database connector as shown and see the behavior by posting another booking request. As the payload is updated to 1 i.e response of database operation, transformation fails due to mismatch in payload.
To avoid original payload getting modified, we can use message enricher component.
Lets bring in a message enricher and move the DB operation inside and set the target to flow variable to hold the database response payload. Note the original payload is store to flow variable called payloadMsg, this is just to initialize the payload properly and this variable is never used in the flow anywhere.
Run and test the project
Lets further modify the flow and assume to call a service. Here sub-flow is called using flow reference inside the message enricher and this captures the response in flow variable. On the transform message both the original payload and response payload are merge as shown.
Re-run the mule application and test it.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.