Contact Us 1-800-596-4880

Mule Message Structure

Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule reached its End of Life on November 2, 2022, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

A Mule message is the part of the Mule event that serves as a container for message content and metadata, typically from external sources, as it is processed within flows of a Mule app.

The Mule message is immutable, so every change to a Mule message results in the creation of a new instance. Each processor in a flow that receives a message returns a new Mule message consisting of these parts:

  • A message payload, which contains the body of the message. For example: the content of a file, a record from a database, or the response to a REST or Web Service request.

  • Message attributes, which are metadata associated with the payload.

mule message structure 82af1

A Mule message is created as part of a Mule event when a Message source in a Mule flow triggers a flow to start, as when an HTTP listener receives a response or each time the Scheduler component triggers an execution of the flow.

For example, when an HTTP listener in a Mule app receives a response, it creates a Mule event with a Mule message that contains the content of the response as its payload along with the metadata associated with that content, such as HTTP headers, as it attributes. Message processors in the flow (such as Core components, File read operations, or the HTTP request operations) can then retrieve, set, and process Mule message data that resides in the Mule event according to their configurations.

Note that in Anypoint Studio, the DataSense Explorer shows the structure of a Mule message at any given point of the flow.

Message Payload

The message payload contains the content or body of a message. For example, the payload can contain the results of an HTTP request, the content of records you retrieve through the Select operation of the Database connector, or the content of a file that you retrieve through a Read operation to the File or FTP connector.

The payload content changes as it travels through a flow when message processors in a Mule flow set it, enrich it, transform it into a new format, extract information from it, or even store it in a Mule event variable and produce a new payload.

You can select the payload of a Mule message through a DataWeave expression that uses the Mule Runtime variable, payload.

For example, a Logger component configured to display the payload of a response to an HTTP request for the JSON content at https://jsonplaceholder.typicode.com/users outputs the following example JSON content in the Studio console:

Example: HTTP Response Payload
[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    }
  },
  {
    "id": 2,
    "name": "Ervin Howell",
    "username": "Antonette",
    "email": "Shanna@melissa.tv",
    "address": {
      "street": "Victor Plains",
      "city": "Wisokyburgh",
      "zipcode": "90566-7771",
      "geo": {
        "lat": "-43.9509",
        "lng": "-34.4618"
      }
    }
  }
]

A Logger component set to display the payload for the output of a File Read operation for a simple JSON file can output the following example JSON content in the Studio console:

Example: File Payload
{ "hello" : "world" }

The next message processor in the flow can then act on this payload, for example, by selecting the value of the JSON object in the payload with payload.'hello' to replace the preceding JSON payload with the string, "world".

Attributes

Attributes contain the metadata associated with the body (or payload) of the message. The specific attributes of a message depend on the connector (such as HTTP, FTP, File) associated with the message. Metadata can consist of headers and properties received or returned by a connector, as well as other metadata that is populated by the connector or through a Core component, such as Transform Message.

You can select attributes of a Mule message through a DataWeave expression that uses the Mule Runtime variable, attributes.

For example, when using the attributes variable to display HTTP response metadata through a Logger component, the Studio console outputs the following example HTTP response attributes:

Example: HTTP Response Attributes
{
   Status Code=200
   Reason Phrase=OK
   Headers=[
      date=Sun, 20 Jan 2019 19:13:51 GMT
      content-type=text/html;
      charset=UTF-8
      transfer-encoding=chunked
      connection=keep-alive
      set-cookie=__cfduid=d03462713a0b2c57c8d2ad3bf311287041548011631;
      expires=Mon, 20-Jan-20 19:13:51 GMT;
      path=/;
      domain=.typicode.com;
      HttpOnly
      x-powered-by=Express
      vary=Origin, Accept-Encoding
      access-control-allow-credentials=true
      cache-control=public, max-age=14400
      last-modified=Tue, 15 Jan 2019 18:17:15 GMT
      via=1.1 vegur
      cf-cache-status=HIT
      expires=Sun, 20 Jan 2019 23:13:51 GMT
      expect-ct=max-age=604800,
      report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
      server=cloudflare
      cf-ray=49c3dc570c2f281c-SJC
   ]
}

The example is a response from an HTTP Request operation to the web page https://jsonplaceholder.typicode.com/users.

Notice that each attribute is a key/value pair separated by an equal sign (=). You access the value of an attribute through its key. For example, when using a connector or component (such as the Logger) in your flow, you can access attributes of an HTTP response or a file that you are reading with the following syntax:

  • attributes.'statusCode' to select an HTTP status code like 200.

  • attributes.headers.'date' to select Sun, 20 Jan 2019 18:54:54 GMT from the header of an HTTP response.

  • attributes.headers.'content-type' to select the HTTP content type application/json.

Note that the quotation marks in attributes.headers."content-type" are necessary to avoid a parsing error. The only valid identifiers for attribute names are numbers, characters, and underscores. Without the quotation marks, the name is parsed like this attributes.headers.content - type.

For File metadata the attributes are different. For example, when using the attributes variable to display File metadata through a Logger component, the Studio console outputs the following example content:

Example: File Attributes
LocalFileAttributes[
  lastModifiedTime=2019-01-20T08:17:55,
  lastAccessTime=2019-01-20T10:54:55,
  creationTime=2019-01-20T08:17:55,
  size=22,
  regularFile=true,
  directory=false,
  symbolicLink=false,
  path=/Users/me/Desktop/myJson.json,
  fileName=myJson.json

Notice that each attribute is a key/value pair (such as fileName=myJson.json). You can select the value of an attribute by referencing its key, for example:

  • attributes.'fileName' to return the file name: myJson.json.

  • attributes.size to return the size of the file: 22.