Enrich payload with new fields using Message Enricher
Observation Notes:
We had a requirement of augmenting the current payload with few extra fields which we need to get from external service and then augment it to current payload.
We’ve used Message Enricher.
For example, we have a incoming Json payload like below
{ "EmployeeID": "92" }
Now you want to enrich your payload with extra fields like below. The two extra fields will have to get from external service and augment it to the original payload
{ "EmployeeID": "92", "Name": "Test Name", "Location": "Test Location" }
The flow goes like this
The message enricher receives the copy of original message payload with just EmployeeID. The message enricher has two components here
1. Http call to exernal service to get the extra details of the employee
2. A transform shape (this is just to convert the response to java object). The transform shape code is like below. It just assigns the payload AS-IS, just changes to java object
%dw 1.0 %output application/java --- payload
Now in the message enricher properties, set it like below
Since we are enriching/augumenting only specific fields, we should use the “Enrich elements” section. And in that, the “Source” section indicates the payload inside the Enricher component (which is the response we got from the http call). And the “Target” section on the right side indicates the payload of the main flow.
so here, it will pick the “location” and “name” fields from the response of the http call, and adds those fields as “EmployeeLocation” and “EmployeeName” in the payload of the main flow.
so the result of the main flow final payload will be as desired like below
{ "EmployeeID": "92", "Location": "Test Location", "EmployeeName": "Test Name" }
Other regular usage of Enricher components are like
Another CASE I:
We want to retain the main payload As-IS but would like to store the response of the http call into a flow variable. Then set the properties of the enricher like below
So here, notice that in the source field we did not mention anything, in this case, after the Enricher component is executed, the output of the enricher component will be stored in the flow variable “postEnrich” as named above. However the main flow payload will still remain the same as the old original payload as below
{ "EmployeeID": "92" }
Another CASE 2:
well…we can play with it in many ways….
No comments yet.
-
Archives
- October 2023 (1)
- October 2022 (2)
- October 2021 (2)
- February 2021 (5)
- January 2021 (4)
- December 2020 (3)
- October 2020 (2)
- August 2020 (1)
- June 2020 (1)
- April 2020 (1)
- February 2020 (1)
- December 2019 (7)
-
Categories
-
RSS
Entries RSS
Comments RSS
Leave a comment