The Mule message is the data which crosses an application through flows. It comprises two main components: message header and payload.
- Message Header: It includes metadata about the message.
- Message Payload: It includes business-specific data.
A Mule message is also integrated into a Mule message object. Some of the Mule message objects may include variables, exception payloads and attachments.
Become a master of Mulesoft by going through this HKR Mulesoft Training!
Variables and Properties:
The metadata inside the message header includes properties that provide helpful information regarding the message. The variables in the message object represent the data on a message.
Variables and Properties have a common format: every variable or property contains a name and a value. The name is the way in which you refer to the variable or property in Mule, and the value is the information stored in it. Therefore name acts as a key of the door, and value acts as the material in the back of the door.
The properties and variables of a message have specific scopes which will define and organize the way they apply to the whole life cycle of that message. The properties send metadata as well as a message to make processing easier and avoid mistakes when the message passes through the transport barrier, either by being sent to a different application or by entering a new flow.
Mulesoft Training Certification
- Master Your Craft
- Lifetime LMS & Faculty Access
- 24/7 online expert support
- Real-world & Project Based Learning
The properties have two major scopes. They are inbound and outbound.
- Inbound properties cannot be changed and are generated automatically by the message source, and they cannot be manipulated or set by the users. They contain metadata related to the message source that will prevent data format scrambling or further processing mishaps in the message life cycle. A message keeps its inbound properties only for the flow duration; its incoming properties do not follow it when a message exits a flow.
- Outbound properties can be changed. They are configured during a flow and become inbound properties when the message is passed from one flow’s outbound endpoint to the different flow’s inbound endpoint through a transport. They will contain metadata like an inbound property, but once the message goes into the flow, an outbound property is applied. Outbound properties can be set by the user by manually entering one by one element into the flow or can be set by Mule automatically. Suppose a message is passed into a new flow through a flow reference rather than a connector. In that case, the outbound properties will remain as outbound properties instead of converting as inbound properties.
Variables are the metadata related to the message set by the user. The variables have three scopes. They are:
- Flow variables are only applicable to the flow where they exist.
- Session variables are applicable to the entire flow of the same application.
- Record variables are only applicable to records processed within a batch.
Variables are temporary information elements about a message that the application should use that processes it instead of conveying it with the message at its destination. This means that Humans can set variables while the properties are set and invoked by the systems. However, strict rules on the use of properties and variables do not exist.
Subscribe to our YouTube channel to get new updates..!
How properties and variables are configured and used?
Mule has three message processors that can be used to define, copy, or delete outbound variables and properties on a message in a flow. Mule will add, copy or delete metadata message object or header when we include these transformers in the flow. A fourth message processor exists: the record variable processor may define or delete variables on a record within a batch. It focuses solely on the message processors that act on the messages.
- Property Transformer: For setting, removing or copying properties on the message’s outbound scope, we can use a property transformer. When a message reaches an outbound endpoint, all properties of the outbound scope are sent with the message as transport-specific metadata.
- Variable Transformer: For setting or removing message’s flow variables related to the current flow, we can use a variable transformer. Variables defined with a variable transformer remain only for the current flow and may not pass through the transport barrier.
- Session Variable Transformer: For setting or removing a message’s flow variables related to the current message throughout its lifecycle, through several flows, servers and applications, we can use a Variable session transformer. Session variables defined with a session variable transformer remain throughout the life cycle of the message irrespective of transport barriers.
[Related Article: Mulesoft Tutorial]
Message Payload:
The payload of the message is the main part of the Mule message as it holds the data that your Mule application deals with. You can use metadata in the message object or message header for communicating information related to your message or prevent it from being altered. The payload does not necessarily remain the same since it moves through a flow. Different message processors within a Mule flow may affect the payload along the way by configuring, enhancing, or transforming it to a new format. You can also retrieve data from a payload into a flow using a MEL expression.
Enriching a message Payload:
In some instances, you may call an external resource and use the response to enhance the payload of the message instead of replacing it. You can do this by using a message enricher scope to encapsulate the message processors performing the information retrieval task. Once this is done, Mule adds or expands the payload of the message with the result of a call to the resource.
Viewing the Mule Message:
A mule message structure can be viewed at any point of the flow. Simply select an element in the flow and click on the DataSense icon. Then DataSense Explorer is opened and shows both the message structure that enters elements and the message structure exits it. It helps know the properties and names of variables which are available at this point, along with the internal structure of the payload.
Conclusion:
In this blog, we have gone through the mule message structure, Mule header, message payload, variables and properties of a message and the way variables and properties of a message are configured. Hope you found this information useful.
Other Blogs:
About Author
Kavya works for HKR Trainings institute as a technical writer with diverse experience in many kinds of technology-related content development. She holds a graduate education in the Computer science and Engineering stream. She has cultivated strong technical skills from reading tech blogs and also doing a lot of research related to content. She manages to write great content in many fields like Programming & Frameworks, Enterprise Integration, Web Development, SAP, and Business Process Management (BPM). Connect her on LinkedIn and Twitter.
Upcoming Mulesoft Training Certification Online classes
Batch starts on 10th Nov 2024 |
|
||
Batch starts on 14th Nov 2024 |
|
||
Batch starts on 18th Nov 2024 |
|