Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Mule Message Structure

A Mule message carries a payload and any attributes through a flow in a Mule app. Connector operations receive and return Mule messages. For example, when an HTTP Listener in a Mule app receives an HTTP request, it creates a Mule message that contains the HTTP body as the payload. The attributes of the message contain the incoming HTTP headers and any metadata populated by the connector.

mule-message-structure-82af1

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 is the body of a Mule message. For example, the payload contains 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.

  • payload: You access the payload through the keyword payload from a connector or component in your flow, and you can use DataWeave selectors, such as payload.someField to access fields within the payload.

The payload typically changes as it travels through a flow as message processors in a Mule flow set it, enrich it, or transform it into a new format. You can also extract information from a payload within a flow using a DataWeave expression and storing it as a variable.

For example, the Transform component is a message processor that can use DataWeave to modify its input payload to a new output. These modifications include changing the set of fields to output or changing the format of the data. For example, you might use it to change the format from XML to JSON. You might exclude a field that contains personal identifiers or private data for a customer, such as the social security or medical record number, or you might add a new field to the output.

Attributes

Attributes contain message metadata that can consist of headers and properties received or returned by a connector, as well as other metadata that is populated by the connector. The metadata available to the message depends on the connector.

You access attributes of a message through the keyword attributes. For example, when using a connector or component (such as the Logger) in your flow, you might access attributes of an HTTP response or a file that you are reading:

  • File metadata examples:

    • attributes.fileName: For getting the name of a file, such as myFile.json.

    • attributes.size: For getting the size of a file, such as 1079.

  • HTTP header examples:

    • attributes.statusCode: For getting the HTTP status code, such as 200.

    • attributes."content-type": For getting the HTTP content type, such as application/json; charset=utf-8.

Note that the quotation marks in attributes."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.content - type.