DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Integrating Salesforce APEX REST
  • What is MuleSoft and Anypoint Platform Capabilities and Strengths
  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration
  • When Production Stops Moving: Running Claude Code Across a Distributed Enterprise Integration Team

Trending

  • Designing Distributed Counters: A Redis Challenge for Frontend Engineers
  • Google Cloud Pub/Sub vs. AWS SNS and SQS: One Java API for Both With MultiCloudJ
  • Should an AI Agent Have Write Access to Your AWS Account?
  • Beyond Semantic Similarity: Designing Two-Stage RAG With Java

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Enterprise Integration Patterns With MuleSoft: Message Enricher

Enterprise Integration Patterns With MuleSoft: Message Enricher

Learn how to enrich your data with everything you need.

By 
Jitendra Bafna
·
Dec. 27, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Introduction

Message or Content Enricher is an enterprise integration pattern that receives an incoming message that doesn't have all the required information, then retrieves that required information from another target system appends it to the data to the message, or forms a new message with everything we need. The image below demonstrates the basic flow.

MuleSoft 3 provides the Message Enricher component. Generally, we wrap the message processor with the Message Enricher component to enrich the data.

In MuleSoft 4, there is no component like the Message Enricher — it has been removed.  This component is replaced by the Target and Target Value attributes with the message processor.

Target and Target Value in MuleSoft 4

  • Target is the basically variable that holds the data (output data of the processor). Names can only include numbers, characters, and underscores.
  • Target Value is output data of the processor that is stored within the target variable. By default, the value is the message payload (payload). The field accepts any value that a variable accepts: any supported data type, DataWeave expressions, the keywords payload, attributes, and message, but not the keyword vars. 

One use case is if you don't want to change your actual payload when a request has been processed by a particular processor. 

We receive the request with the payload and, after it passes through one of the processors, the payload will be the output of that processor, but we don't want to change the actual payload. In such cases, you can make use of  the Target and Target Value, and the output of that processor will be stored in the Target variable instead of replacing the actual payload with the output of the processor.

Here is a video tutorial explaining step by step how to enrich data with Target and Target Values in MuleSoft.

Code

XML
 




x
45


 
1
<?xml version="1.0" encoding="UTF-8"?>
2

          
3
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file"
4
    xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
5
    xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce" xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
6
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd
7
http://www.mulesoft.org/schema/mule/salesforce http://www.mulesoft.org/schema/mule/salesforce/current/mule-salesforce.xsd
8
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
9
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
10
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
11
    <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="9c0ac87d-f684-48f1-a745-5ef1c714afee" >
12
        <http:listener-connection host="0.0.0.0" port="8081" />
13
    </http:listener-config>
14
    <flow name="batch-process-demoFlow" doc:id="f7753551-7534-4d21-9251-8fa22b838777" >
15
        <http:listener doc:name="Listener" doc:id="913a9c63-b367-4c5c-b6c4-a5ab5480e951" config-ref="HTTP_Listener_config" path="/api/enrich"/>
16
        <flow-ref doc:name="Flow Reference" doc:id="f88822ec-8191-4157-a34d-09a2a5ef34db" name="batch-process-demoSub_Flow" target="vRespData"/>
17
        <logger level="INFO" doc:name="Original Payload Logger" doc:id="ef162a90-8b32-4670-8561-211233b37deb" message="Original Payload: #[payload]"/>
18
        <logger level="INFO" doc:name="Response Data Payload" doc:id="2bb45828-9f70-432c-a521-69083d0b4ae4" message="Response Payload: #[vars.vRespData]"/>
19
        <ee:transform doc:name="Enriched Data" doc:id="2fd0201a-8137-495c-96a4-12128a733291" >
20
            <ee:message >
21
                <ee:set-payload ><![CDATA[%dw 2.0
22
output application/json
23
---
24
{
25
    city: payload.city,
26
    region: payload.region,
27
    ip_address: vars.vRespData.client_ip,
28
    datetime:vars.vRespData.datetime,
29
    timezone:vars.vRespData.timezone,
30
    utc: vars.vRespData.utc_datetime,
31
    dayOfYear: vars.vRespData.day_of_year
32
}]]></ee:set-payload>
33
            </ee:message>
34
        </ee:transform>
35
    </flow>
36
    <sub-flow name="batch-process-demoSub_Flow" doc:id="3f04f187-37d3-47d7-8b1a-612f7275b8d1" >
37
        <http:request method="GET" doc:name="Enriched Request" doc:id="d721546f-af82-444a-925d-13e36f79701d" url="http://worldtimeapi.org/api/timezone/{region}/{city}">
38
            <http:uri-params ><![CDATA[#[{
39
    region: payload.region,
40
    city: payload.city
41
}]]]></http:uri-params>
42
        </http:request>
43
    </sub-flow>
44
</mule>



Now you know how to implement a Message Enricher with MuleSoft.

MuleSoft Enterprise integration

Opinions expressed by DZone contributors are their own.

Related

  • Integrating Salesforce APEX REST
  • What is MuleSoft and Anypoint Platform Capabilities and Strengths
  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration
  • When Production Stops Moving: Running Claude Code Across a Distributed Enterprise Integration Team

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook