Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Mule Message Data and Expression Language

DZone's Guide to

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.

· Integration Zone ·
Free Resource

The State of API Integration 2018: Get Cloud Elements’ report for the most comprehensive breakdown of the API integration industry’s past, present, and future.

Accessing 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.

Image title

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.

Image title

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.

Image title

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 

Image title

Inbound message properties :

  • These message properties are read only.

  • Query parameters, URI parameters, Method name, and Content-type are examples of inbound properties.

Image title

Outbound message properties:

  • We can use the Set Property transformer to set outbound properties.

Image title

Payload representation:

  • This is a core part of Mule Message.

  • We can use Set Payload or the Ddataweave Transformer to modify payloads accordingly.

Image title

Setting message properties:

Image title

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.

Image title

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:

Image title

Context Objects:

Image title

Accessing message data:

Image title

Accessing message payload data:

Image title

Accessing relational map data :

Image title

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')]

Your API is not enough. Learn why (and how) leading SaaS providers are turning their products into platforms with API integration in the ebook, Build Platforms, Not Products from Cloud Elements.

Topics:
mule ,mule flow ,mule developer ,integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}