In MuleSoft, the payload refers to the main data being passed through the message in a Mule flow. It can be of various types, such as a string, a JSON object, or an XML document. It is used as the input and output for message processors in a Mule flow, and can be accessed and manipulated using the Mule expression language (MEL).
When to use variable vs payload – MuleSoft
In MuleSoft, the
payload refers to the main data being passed through the message in a Mule flow, while a
variable is a temporary storage location that can be used to store data that is used within a flow.
It is recommended to use
payload as the main data carrier as it is the main data being passed through the message in a Mule flow. However, you may use
variable when you want to store a temporary data, such as a calculation, intermediate results, or a value that you want to use later in the flow.
For example, you might use a variable to store a calculated total from a series of database lookups and then use that variable to set the value of a message header or to pass it to another message processor.
Another example where variable comes in handy is when you want to pass a value from one flow to another flow. You can set the value to a variable and use that variable in another flow.
In summary, you should use payload to transport data and variable to store the data that you want to use later in the flow or want to pass to another flow.
MuleSoft Transform Message Payload
What does the Payload of a Mule Message Always Contain?
The payload of a Mule message always contains the data being passed through a Mule flow. This data can be of any type, such as a string, a JSON object, an XML document, a binary file, etc. Depending on the connector or operation being used, the payload may be automatically extracted from the message, or it may need to be explicitly set. The payload can be accessed and manipulated within a Mule flow using the
#[payload] expression, and it can be set or overwritten using the