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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Integrating Salesforce APEX REST
  • What is MuleSoft and Anypoint Platform Capabilities and Strengths
  • Implementing Enterprise Integration Patterns With MuleSoft: Message Routing
  • MuleSoft OAuth 2.0 Provider: Password Grant Type

Trending

  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • How Can Developers Drive Innovation by Combining IoT and AI?
  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  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 user avatar
Jitendra Bafna
DZone Core CORE ·
Dec. 27, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
8.0K Views

Join the DZone community and get the full member experience.

Join For Free

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
  • Implementing Enterprise Integration Patterns With MuleSoft: Message Routing
  • MuleSoft OAuth 2.0 Provider: Password Grant Type

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!