Mule Message Data and Expression Language
We take a look at Mule Express Language (MEL), what it can be used to do, as well as how to use the data generated by Mule Message.
Join the DZone community and get the full member experience.
Join For FreeAccessing information about Mule messages using Datasense :
DataSense is Anypoint Studio’s ability to proactively discover metadata from internal and external resources.
Keeps you from having to manually discover information about the data.
Facilitates transformations by providing DataWeave expected input or output.
We saw this with Transform Message component.
Other ways to view message information :
Add a Logger component to a flow and view its output in the Anypoint Studio console.
Use the Anypoint Studio Visual Debugger which is the most comprehensive way. We also have a Mule Expression Evaluator.
Use autocomplete when writing expressions in the Anypoint Studio Visual Editor.
Reviewing the structure of Mule messages:
Mule message is a core part of mule applications.
Message processors may or may not modify Mule messages.
We can enrich Mule messages through Message Enricher which is a part of Mule's advanced training.
Message Properties :
Inbound properties
Set from the message source
Read-only access
Persist throughout the flow
Outbound properties
Added by
Read/write access
Can set, remove, copy
Inbound message properties :
These message properties are read only.
Query parameters, URI parameters, Method name, and Content-type are examples of inbound properties.
Outbound message properties:
We can use the Set Property transformer to set outbound properties.
Payload representation:
This is a core part of Mule Message.
We can use Set Payload or the Ddataweave Transformer to modify payloads accordingly.
Setting message properties:
Debugging applications with the Mule Debugger:
Locate the port used by the Mule Debugger.
Add a breakpoint, debug an application, and step through the code.
Use the Mule Debugger to view message properties.
Pass query parameters to a request and locate them in the Debugger.
You can add breakpoints to processors and step through the application.
By default, Debugger listens for incoming TCP connections on localhost port 6666.
Mule Expression Language (MEL):
Use MEL to access and evaluate the data in the payload, properties, and variables of a Mule message.
MEL is a lightweight, Mule-specific expression language.
Accessible and usable from within virtually every message processor in Mule.
Is used to modify the way the processors act upon the message such as routing or filtering.
Makes use of Mule-specific context objects.
Case-sensitive.
Easy to use with autocomplete everywhere.
Basic MEL Syntax:
Context Objects:
Accessing message data:
Accessing message payload data:
Accessing relational map data :
Accessing relational map data :
Evaluation: ==, !=, >, <, >=, <=, contains, is #[message.inboundProperties.'http.query.params'.lastname != null]
The literal empty tests the emptiness of a value.
XPath: #[xpath('expression')]
RegEx: #[regex('expression')]
Opinions expressed by DZone contributors are their own.
Comments