Studio Visual Editor
-
Within the Palette, click Miscellaneous, then drag Custom Business Events to the desired location in your flow. Double-click the icon to open the Properties pane.
-
Enter string values for Display Name and Event Name.
-
Optionally, create a list of Key Performance Indicators (KPIs) to capture information from the message payload. For each KPI, enter a name (which can be used in the search interface of Mule Management Console or CloudHub at runtime), and a value, which may be any Mule expression.
Note that key/value pairs can vary according to your business needs. Additional examples:
Name Expression/Value price
700
price-after-discount
#[groovy:payload.price]
price-after-discount
The price for the item is:#[groovy:payload.price]
Using the XML editor, you can set up your flow so that metadata can be shared among events. See the XML tab for details on how to set up the tracking:custom-event-template
global element in your flow.
You can also trigger conditional custom events to help track how messages are processed through your flow. For example, you could set up a choice router in your flow like this:
In this example, a custom event with the event name "success" is fired if the debug flag is on when the message processor is invoked. Otherwise, a custom event with the event name "failure" is fired.
Studio or Standalone XML
Configure a custom event using XML as in the following example:
<flow name="flow">
...
<tracking:custom-event event-name="Retrieved Employee">
</tracking:custom-event>
...
</flow>
When you define a custom event, you can also add metadata. Use Mule expression language in the value to capture information from the message payload.
<flow name="flow">
...
<tracking:custom-event event-name="Retrieved Employee" doc:name="Retrieved Employee">
<tracking:meta-data key="Employee Id" value="#[payload['ID']]"/>
<tracking:meta-data key="Employee First Name" value="#[payload['FIRST_NAME']]"/>
<tracking:meta-data key="Employee Last Name" value="#[payload['LAST_NAME']]"/>
<tracking:meta-data key="Employee Email" value="#[payload['EMAIL']]"/>
<tracking:meta-data key="Employee Git ID" value="#[payload['GITHUB_ID']]"/>
</tracking:custom-event>
...
</flow>
You can even add text to the expression language, as shown in the following example:
<flow name="flow">
...
<tracking:custom-event event-name="price_discount">
<tracking:meta-data key="price-after-discount"
value="The price for the item is:#[groovy:payload.price]" />
</tracking:custom-event>
...
</flow>
Also, metadata can be shared among events using the tracking:custom-event-template
global element:
<tracking:custom-event-template name="template">
<tracking:meta-data key="tier-level" value="platinum" />
<tracking:meta-data key="price-after-discount" value="#[groovy:payload.price]" />
</tracking:custom-event-template>
<flow name="flow">
<tracking:custom-event event-name="event1" inherits="template" />
<tracking:custom-event event-name="event2" inherits="template" />
</flow>
And you can define how conditional custom events are fired. The code below shows how to do this:
<choice>
<when expression="INVOCATION:debugflag = on" evaluator="header">
<tracking:custom-event event-name="success" />
</when>
<otherwise>
<tracking:custom-event event-name="failure" />
</otherwise>
</choice>
In this last example, a custom event with the event name "success" is fired if the debug flag is on when the message processor is invoked. Otherwise, a custom event with the event name "failure" is fired.