Sensors in BPEL
When using BPEL with Business Activity Monitoring it is necessary to instrument the BPEL process with sensors to track activities within the BPEL process. Lets look at the concepts associated with this.
What is BAM?
Business Activity Monitoring allows business users real time access to the state of various metrics and key performance indicators within their business. Obviously a key component of this is access to the state of the business processes currently executing within the business. BAM dashboards provide business users with a quick overview of the key performance indicators that they need to monitor. The Oracle BAM solution also provides for alerts to be raisesd to inform business users when key thresholds are breached.
How does BPEL communicate with BAM?
The Oracle BPEL Process Manager allows the insertion of "sensors" into the BPEL process. These sensors are attached to individual activities within a BPEL process, such as an invoke, a scope or a receive. Sensors can fire when an activity starts, when it completes, when compensation is invoked, when it is retried, when it throws an exception or all of the above.
Sensor events are routed to "Sensor Actions". When communicating with the Oracle BAM environment this sensor action may be a message queue. Sensor events may be associated with multiple actions, such as a message queue and a database.
Sensor events have an XML document associated with them, providing context information to the BAM environment.
Are Sensors Part of the BPEL Standard?
BAM functionality is not actually part of the BPEL spec. Oracle BPEL Process Manager extends the functionality of BPEL by having an additional file - sensors.xml - that relates sensors to actions in a BPEL process. Because no sensor information is included in the BPEL document itself the BPEL document remains as standard BPEL. However when the additional file is deployed alongside the BPEL process then the Oracle BPEL Process Manager can provide sensor data to the BAM solution. This is a neat solution that provides additional funcitonality to BPEL without the need to have a non-standard BPEL process description.
Adding a Sensor to BPEL
The BPEL Designer provides support for adding sensors. To add a sensor to the activity just double click the activity to bring up the activity editor and select the sensor tab.
You can now create a sensor for this activity by clicking create. This brings up the "Create Activity Sensor" dialog which allows us to create the sensor and decide when it will fire.
We need to assign the sensor to one or more sensor actions if we want anything to actually happen. To do this we create a new sensor action of an appropriate type.
In the example below we have chosen to use a message queue that is reached via a JNDI location. The configuration of the queue is app server specific, for exampe for OC4J this will be defined in the jms.xml file.
As discussed above we can have multiple sensor actions associated with a sensor. In the example below we also have a database sensor action that writes data into a database table within the BPEL repository.
It is also necessary to associate the sensor with a least one data element. Failure to do this can cause problems when working with BAM.
What do I get for my Money?
So the question now is why would I bother instrumenting my code. Well, BPEL PM is good at monitoring an individual process, but it is not good at consolidating the results of many processes, or raising alerts if parameters drift out of acceptable norms. Here are some of the things that BAM can do, when given a suitable event feed from a BPEL process.
- Calculate event durations and raise alerts if average event duration or individual event duration exceeds specific thresholds.
- Provide statistics on the number of processes at a particular stage of the process.
- Provide cumulative information about processes in flight - for example the amount of revenue expected to be received based on sales processe currently in flight.
- Raise an alert if a certain percentage of events exceed a threshold, for example if more than 10% of loan requests are approved with bad credit.
- ...