Wednesday, August 18, 2010

BPEL Scheduling: Quartz and Database

A common requirement in many SOA projects is to schedule BPEL processes to run at specific time. Now there are various scheduling mechanisms which can be used for doing this. In this post I will be discussing about 2 approaches which I have used :
1. Using Open source Quartz scheduler.
2. Scheduling your process from Database using dbms_scheduler apis.

In Oracle BPEL open source job scheduler, Quartz is implemented as part of java class called DefaultSchedulerCalloutImpl. Incase your BPEL process is triggered by a file/ftp adapter you can modify the bpel.xml file to make use of the quartz scheduler.

<activationAgents>
<activationAgent className="oracle.tip.adapter.fw.agent.jca.JCAActivationAgent"
partnerLink="ReadFile" heartBeatInterval="10">
<property name="portType">Read_ptt</property>
<property name="schedulerCallout">DefaultSchedulerCalloutImpl</property>
<property name="endpointScheduleOn">0 0 8 * * ?</property>
<property name="endpointScheduleOff">0 0 10 * * ?</property>
</activationAgent>
</activationAgents>

The above piece of code is direction to the activation agent to activate the BPEL process between 8 and 10 am everyday and heartbeat interval of 10 seconds indicates how frequently the process is active for polling.

The 2nd approach is a simple solution based on Oracle dbms_scheduler api. Basically you need to have your BPEL process read from a DB table which gets populated by the DBMS job at a particular frequency. I am sharing some sample code below which can be reused after making modifications.

Create table bpelschedulertable (process_name varchar2(20));

Script to create the scheduler job.

/* Drop Jobs if they exist */
BEGIN
DBMS_SCHEDULER.DROP_JOB(JOB_NAME => 'BpelScheduledJob');
END;
/

/* Create Scheduled Job */
BEGIN
 DBMS_SCHEDULER.CREATE_JOB(
 JOB_NAME => 'BpelScheduledJob',
 JOB_TYPE => 'PLSQL_BLOCK',
 JOB_ACTION => 'BEGIN INSERT INTO bpelschedulertable (PROCESS_NAME) VALUES (''samplebpel'');COMMIT;END;',
 START_DATE => TO_DATE('2010-08-18 12:00:00','YYYY-MM-DD HH24:MI:SS'),
 REPEAT_INTERVAL => 'FREQ=MINUTELY;INTERVAL=15',
 COMMENTS => 'Scheduled for every 15 minutes');
 DBMS_SCHEDULER.ENABLE(NAME => 'BpelScheduledJob');
 END;
/

That's it ! Your BPEL process(samplebpel) should trigger every 15 minutues now.

Scripts to monitor/manage the scheduled job.

select * from dba_scheduler_jobs ;

/*Command to enable job*/
Begin    
dbms_scheduler.enable('BpelScheduledJob');  
end;

/*Command to disable job*/
Begin
Dbms_scheduler.Disable('BpelScheduledJob');
end;

/*Command to change the repeat interval of the job*/
Begin
Dbms_scheduler.set_attribute(name=>'BpelScheduledJob',attribute=> 'REPEAT_INTERVAL', value=> 'FREQ=HOURLY;INTERVAL=1');
end;

7 comments:

  1. Really very nice post.
    How to use same Quartz scheduling in SOA 11g[11.1.1.x]? In BPEL 11g there is no bpel.xml...

    Thanks,
    Avi

    ReplyDelete
  2. @Avi

    I haven't used Quartz scheduler in SOA 11g, so not sure about supportability of the activation agent parameters in composite.xml.

    However you can check below blog entries for more info./alternatives of using Quartz scheduling mechanism in SOA 11g.

    http://blogs.oracle.com/sdhurjati/2011/01/ready_to_use_quartz_scheduler.html

    http://blogs.oracle.com/sdhurjati/2011/01/enahced_ready_to_use_quartz_sc.html

    ReplyDelete
  3. hi
    can you please elaborate in a step by step manner with logical explanation in regards with using dbms_scheduler,couldn't get how will the database invoke the process and how will it recognise the bpel process.can u please throw some more light on it

    ReplyDelete
    Replies
    1. All that the dbms_Scheduler api is doing is running some PLSQL code to insert some data into a table, next the BPEL process is configured (Receive activity is a DB adapter) to poll this table. So as and when the scheduler will run and insert a record into the table, an instance of BPEL process is triggered

      Delete
  4. Rubicon Red has a Scheduler designed specifically for the Oracle SOA Suite. We have just announced the beta release of version 2.0.

    Designed specifically as an extension to Oracle SOA Suite, the Rubicon Red Scheduler provides the ability schedule the execution of Web Services, BPEL Processes and the publication of EDN Events.

    If you are interested in signing up for the Beta please see the following link.

    http://www.rubiconred.com/news/rubicon-red-announces-beta-release-of-scheduler-2-0/

    ReplyDelete