Tuesday, December 6, 2011

Oracle SOA Suite – Scheduling the composites using Quartz scheduler.

Oracle SOA Suite – Scheduling the composites using Quartz scheduler.

This blog will explain the approach to schedule the Oracle SOA Suite composites using the Quartz scheduler.

Approach to schedule the Oracle SOA Suite 11g composites 

Create the ADF binding to the composite.xml

Open the composite xml


Copy the service section and give a unique name e.g. bpelhelloworld_client_adf and also make sure the ServiceName specified is correct.


Copy the client partnerlink wire and edit the name of the copied wire as adf service name specified in the previous step.





Open the design mode and verify the wires.



Create the JOB class that invokes the composite service.

Create the JOB class as shown below to invoke the composite service, change the soa server details and the composite details accordingly.

package javaschedule;
import java.util.Hashtable;
import java.util.UUID;
import java.util.logging.Logger;
import oracle.soa.management.facade.*;
import javax.naming.Context;
import oracle.soa.management.util.*;
import oracle.fabric.common.NormalizedMessage;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
public class BPELHelloWorldJob implements Job {
Logger logger;
public BPELHelloWorldJob() {
logger = Logger.getLogger(this.getClass().getName());
}
public void execute(JobExecutionContext jobExecutionContext) {
try {
System.out.println("initiated");
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL, "t3://soahost:soaport/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxxx");
jndiProps.put("dedicated.connection", "true");

Locator locator = null;

String inputPayload ="<ns1:process xmlns:ns1=\"http://xmlns.oracle.com/JavaSchedule/BPELHelloWorld/BPELHelloWorld\"><ns1:input>Albin</ns1:input></ns1:process>";
locator = LocatorFactory.createLocator(jndiProps);
// find composite
Composite composite = locator.lookupComposite("default/BPELHelloWorld!1.0");

System.out.println("Got Composite : "+ composite.toString());

// find exposed service of the composite
Service service = composite.getService("bpelhelloworld_client_adf");
System.out.println("Got serviceName : "+ service.toString());
// make the input request and add this to a operation of the service
NormalizedMessage input = new NormalizedMessageImpl();
// payload is the partname of the process operation
input.getPayload().put("payload",inputPayload);
// process is the operation of the employee service


service.post("process", input);

} catch (Exception e) {
e.printStackTrace();
}
logger.fine("Call HelloWorld BPEL Process Finished");
}
}



3. Create the client that schedule the JOB
Change the cron expression accordingly to change the scheduling period.


package javaschedule;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;
public class ProcessScheduler {
public ProcessScheduler() {

try {

StdSchedulerFactory schedFact = new StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
System.out.println(sched);
sched.start();
JobDetail jd =new JobDetail("BPEL Hello World Job", "BPEL Job", BPELHelloWorldJob.class);
CronTrigger cronTrigger =new CronTrigger("BPEL Hello World Job", "BPEL Job");
String cronExpr = null;
//every five min
cronExpr ="0 0/5 * * * ?";
cronTrigger.setCronExpression(cronExpr);
sched.scheduleJob(jd, cronTrigger);

} catch (Exception e) {
e.printStackTrace();

}
}
public static void main(String[] args) {
ProcessScheduler cl=new ProcessScheduler ();
System.out.println("Scheduled JOB");
}

}

Execute the client

 java javaschedule .ProcessScheduler, this will schedule the JOB every 5 minutes to invoke the composite service.

DOWNLOAD SAMPLE


8 comments:

  1. Rubicon Red provide an out of the box scheduler for the Oracle SOA Suite, enabling you to schedule:

    - Execution of a synchronous web service
    - Execution of one way or two way asynchronous web service
    - Publication of an EDN event to the SOA Suite Event Delivery Network

    See http://www.rubiconred.com/scheduler for further details

    ReplyDelete
  2. Hi Albin,
    I am trying to implement Scheduler in SOA 11g have followed the above mentioned process but I do not find any instances running.Should we create a WAR file to deploy the Java Schedule? am a newbie to java and SOA please help me.

    Regards,
    Harry

    ReplyDelete
  3. Even you can create a war and deploy but i don't thing the issue is with that.

    May be the issue is with invoking the Composite process from the java code.

    1. Check whether job is executed successfully
    2. Check if there is any exception when invoking the Composite process.

    Regards
    Albin I

    ReplyDelete
  4. Hi Albin,

    Hope you are doing great.

    I have a question regarding scheduler, do you know of any out-of-box mechanism in SOa where we can monitor whether a scheduler is running or not and if its not a notification should be triggered.

    -Surya.

    ReplyDelete
  5. Thông tin của tác giả cũng hoàng hảo, cám ơn bạn đã share.
    Trang tham khảo : Thạch anh vụn

    ReplyDelete
  6. Bài post của Admin quá hay, thank bạn đã share.
    Page hữu ích : Gia công thạch anh

    ReplyDelete
  7. Thông tin của admin cũng hữu ích, cám ơn bạn vừa chia sẻ.
    Xem thêm tại website: Vòng thạch anh

    ReplyDelete
  8. Bài post của tác giả hay, cám ơn bạn đã share.
    Trang tham khảo : Tỳ hưu đá thạch anh

    ReplyDelete