Friday 8 March 2019

Mule 4 Event Model

Mule Event and Mule Message:
When a request reaches the Event source of a flow (such as an HTTP request
 or a change to a database or file).  A mule event will be generated it creates mule event object. Mule event object primarily consists of information required to process by the Mule runtime. Mule event object travels through all the components configured in mule flow.

Mule event object is immutable, so every change to an instance of a Mule event object results in the creation of a new instance.
A Mule Event object is composed of these objects:
  1. A Mule Message contains a message payload and its associated attributes.
  2.  Variables are Mule event metadata that you use in your flow.

The sequence of the activities happens when event source receives the trigger
  • A trigger reaches the event source.    
  • The event source produces a Mule event.
  •  The Mule event travels sequentially through the components of a flow.Each component interacts in a pre-defined manner with the Mule event

How the Mule Event object get created from the incoming request ?
Standard message structure consists of Header and Payload parts, where Payload is core business information that need to processed and Header contains details about payload like encryption schemes, security credentials etc. Header content also called metadata. 

When a standard message reaches the Mule Event source (in other words its called Inbound Endpoint), Event source converts that message to Mule Event Object as Mule Event processors can only understand only Mule Event object. and handovers to next event processor.

Mule Event source creates Mule Event object by coping Header contents to Attributes section and Payload contents to Payload section

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="" xmlns:file=""
xmlns:doc="" xmlns:xsi="" xsi:schemaLocation="">
<file:config name="File_Config" doc:name="File Config" doc:id="ce7b6ee8-e9f2-4370-b17f-2adf413d9826" >
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="825c4787-27c3-4595-baa3-5fa66d3ca97f" >
<http:listener-connection host="" port="8081" />
<flow name="mule_event_demoFlow" doc:id="1bbf3a21-775f-49eb-9d06-48bb9f9a51dd" >
<http:listener doc:name="Listener" doc:id="a287d233-9054-423c-818d-e73a1fa67b51" config-ref="HTTP_Listener_config" path="/"/>
<logger level="INFO" doc:name="Logger" doc:id="cb41a866-d0a9-4a06-b7f4-5f75b3c62272" message="The City from source is #[message.attributes.headers.City]"/>
<set-payload value="This payload is returned to client" doc:name="Set Payload" doc:id="2ab7bb3e-3943-4da1-9c54-c76907348924" />

No comments:

Post a Comment

How to Design Mule API to process Attachments

This blog Explains , how to design Mule API to process attachments. Quite often we get requirement to design API's that process attachme...