BPEL: Scheduling Processes
Introduction
All we know that, Oracle BPEL process instance can be initiate in number of ways. Like
Passive: BPEL engine receives a call (BPEL console or some other web service)
Active: BPEL engine looks for events to be occur that should trigger new instance of process.( Polling for file in particular folder and polling for new record in database table)
There is intermediate option where BPEL engine will start process instance at specific time (schedule).
This document talks more about scheduling BPEL process using various methods like Quartz scheduler and Wait activity.
Quartz : Scheduling Endpoint Activation
Quartz is full featured, open source job scheduling system, that can integrated with any J2EE and J2SE applications.
In BPEL Process Manager, quartz is implemented as part of java class called DefaultSchedulerCalloutImpl .
To understand scheduling process, we will take a sample business scenario.
Sample Business Case : Consider the case where process need to poll for a file at every day 7PM to 7:30PM.
Actual Solution : Create a BPEL process in such way that it has to poll for particular file at some location of server by using file adaptor configuration wizard.
Consider an example where BPEL process named ScheduleBPELProcess is created to poll for particular file (File Adaptor Inbound Service) and write the file information into database table.(In this example we have used oracle database 10g). Process contains receive activity( to receive payload from file adaptor), Invoke activity ( To write payload to database) and Transform activity to map source data and destination data.
This BPEL process will be keep on polling for particular file every time (24X7) as per polling frequency defined in configuring file adaptor wizard at design time.
But our requirement is to schedule the above BPEL process in such way that , the process should poll only at specific time like 7PM to 7:30 PM. To achieve this functionality we need to add below piece of code in bpel.xml file of the BPEL process.
Open bpel.xml file and add the below code. You can check below screen shot for your reference. We will understand each and every component of below piece of code in subsequent manner
<activationAgents>
<activationAgent className="oracle.tip.adapter.fw.agent.jca.JCAActivationAgent"
partnerLink="readFileService" heartBeatInterval="10">
<property name="schedulerCallout">DefaultSchedulerCalloutImpl</property>
<property name="endpointScheduleOn">0 0 19 * * ?</property>
<property name="endpointScheduleOff">0 30 19 * * ?</property>
</activationAgent
</activationAgents>
Activation Agent is one which makes endpoint of adaptors active. Always you should have input for adaptor endpoints to start your process. In the above example readFileService partner link is active end point of BPEL process.
The activation agent called “ heartbeat” that does scheduling action.
The heartBeatInterval is measured in seconds, it specify that how frequently the schedule is checked.
Quartz is implemented as part of java class named DefaultSchedulerCalloutImpl. The quartz scheduler turns heartbeat on and off.
The next properties in scheduler code is endpointScheduleOn and endpointScheduleOff. Through these properties we will set the scheduling time for polling mechanism. The attribute for endpointScheduleOn and endpointScheduleoff element is cron sequence.
Cron sequence is unix utility that allow tasks to be automatically run in the background at regular intervals.
This cron Sequence follows the specified set of syntax. In the above code cron sequence is as follows.
<property name="endpointScheduleOn">0 0 19 * * ?</property>
<property name="endpointScheduleOff">0 30 19 * * ?</property>
Here 0 0 19 * * ? and 0 30 19 * * ? specify that process should fire everyday between 7PM and 7:30PM.
Cron sequence is a string comprised of 6 or 7 fields separated by whitespace. The 7th field is optional.
Field Name |
| Allowed Values |
| Allowed Special Characters |
Seconds |
| 0-59 |
| , - * / |
Minutes |
| 0-59 |
| , - * / |
Hours |
| 0-23 |
| , - * / |
Day-of-month |
| 1-31 |
| , - * ? / L W C |
Month |
| 1-12 or JAN-DEC |
| , - * / |
Day-of-Week |
| 1-7 or SUN-SAT |
| , - * ? / L C # |
Year (Optional) |
| empty, 1970-2099 |
| , - * / |
Here are the some examples for cron sequence.
Expression |
| Meaning |
"0 0 12 * * ?" |
| Fire at 12pm (noon) every day |
"0 15 10 ? * *" |
| Fire at 10:15am every day |
"0 15 10 * * ?" |
| Fire at 10:15am every day |
"0 15 10 * * ? *" |
| Fire at 10:15am every day |
"0 15 10 * * ? 2005" |
| Fire at 10:15am every day during the year 2005 |
"0 * 14 * * ?" |
| Fire every minute starting at 2pm and ending at 2:59pm, every day |
"0 0/5 14 * * ?" |
| Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day |
"0 0/5 14,18 * * ?" |
| Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day |
"0 0-5 14 * * ?" |
| Fire every minute starting at 2pm and ending at 2:05pm, every day |
"0 10,44 14 ? 3 WED" |
| Fire at 2:10pm and at 2:44pm every Wednesday in the month of March. |
"0 15 10 ? * MON-FRI" |
| Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday |
"0 15 10 15 * ?" |
| Fire at 10:15am on the 15th day of every month |
"0 15 10 L * ?" |
| Fire at 10:15am on the last day of every month |
"0 15 10 ? * 6L" |
| Fire at 10:15am on the last Friday of every month |
"0 15 10 ? * 6L" |
| Fire at 10:15am on the last Friday of every month |
"0 15 10 ? * 6L 2002-2005" |
| Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005 |
|
|
|
For more details on cron sequence locate the below URL.
http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html
Happy Learning - Veeresh Hawalkhod
Comments
I would like to instantiate a BPEL process once: after server startup or BPEL process activation. It is a long-running process that should be always-on.
Is it possible to use this mechanism? If so, what syntax should I use for "trigger-on-act ivation"?
Thank s!
I am new to BPEL and workflow orchestartion.H ence wanted to know what would be the primary skill sets needed for development using Oracle 10g SOA Suite.I have Java/J2ee skill sets with fair database skills.Would this suffice or do we need a person with strong database skills
Thanks
Subbu
Very helpful article. Keep posting such good articles .
Way to go Veeresh!
-Shar an
Good one, keep going...
Organi sed document in simple terms.
Sachin
Good article. But I had some difficulty understanding the CRON sequence. I am trying to schedule a process to poll every 60s, 24x7. I tried various things to make it happen but I am unable to get it right. Can you please help me out
Can U please tell me how to schedule a bpel task in 11.1.1.5.0.
Tha nks,
Srini.
Rubicon Red provide an out of the box scheduler for the Oracle SOA Suite, enabling you to schedule the execution of a BPEL Process on a regular basis.
Like the example above, it leverage's Quartz for Scheduling, however you don't need to define a File Adapter (or any other adapter) to trigger the BPEL Process, so can be used to trigger any BPEL Process, or a Web Service (including SCA Composite, OSB Proxy Service) as well as the publication of an EDN Event to the SOA Suite Event Delivery Network.
You can also use it within a BPEL Process to dynamically schedule another process
It provides full cluster support (it uses Coherence to manage this). See Oracle SOA Suite Scheduler for further details.
RSS feed for comments to this post