Studio Visual Editor
-
Within the Palette, search for and drag Custom Business Events to the desired location in your flow. Click the icon to open the Properties Editor.
-
Enter string values for Display Name and Event Name.
-
Optionally, click the green plus sign to create a list of Key Performance Indicators (KPIs) to capture information from the message payload. For each subsequent KPI, click the green plus sign:
-
After you click the green plus sign, Studio displays tracking:meta-data.
-
Click tracking:meta-data and a field appears to enter text:
-
Enter a name that can be used in the search interface of Mule Management Console or CloudHub at runtime, and a value, which may be any Mule expression.
In this example the values are:
Name Expression/Value Employee ID
#[payload['ID']]
Employee Email
#[payload['Email']]
Employee Git ID
#[payload['GITHUB_ID']]
-
Note that key/value pairs can vary according to your business needs. Additional examples:
Name | Expression/Value |
---|---|
|
|
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.
XML Editor or Standalone
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.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<flow name="bizFlow">
<tracking:custom-event event-name="Retrieved Employee" doc:name="Custom Business Event">
<tracking:meta-data key="Employee ID" value="#[payload['ID']]"/>
<tracking:meta-data key="Employee Email" value="#[payload['Email']]"/>
<tracking:meta-data key="Employee Git ID" value="#[payload['GITHUB_ID']]"/>
</tracking:custom-event>
</flow>
</mule>
You can even add text to the expression language, as shown in the following example:
<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>
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.