The Scheduler Binding Component (BC), powered by OpenSymphony Quartz
, affords scheduling capability to kick off (consume) other JBI component providers, for example a BPEL Service Engine.
Like other Binding Components such as File or JMS, in order to use Scheduler BC one has to first create a WSDL Document defining the Scheduler binding and then use it to construct a BPEL service to act as a provider endpoint. When the scheduler triggers, a message will be sent to the Business Process and it'll be incumbent on the business logic implemented there to perform an appropriate task.
The Scheduler BC works pretty much the same as any other, such as File BC. However, with the recent WSDL Binding Wizard changes across the board for all BC's, it's worth mentioning how to create a deployment for a Scheduler BC triggering a BPEL to write to a File BC.
Create a Scheduler WSDL Document
- Launch the WSDL Binding Wizard by right-clicking over the Process Files folder of a BPEL project and select New | WSDL Document
- Or equivalently, select New | Other | ESB (Category) | Binding (File Type) from the Process Files context menu
- Enter an appropriate File Name for the WSDL, choose Concrete WSDL Document for the WSDL Type, select SCHEDULER from the Binding drop-down box and press Next
- To create a Simple trigger, choose Simple from the Add combo box or if so already, simply press the + (plus) button, key in appropriate data and press Add Simple Trigger button when done
- Optionally, define a custom date and time format to be used with the scheduler; this format is used both to interpret date and time values persisted in the Scheduler's WSDL as well as displaying the date and time in the message sent to the endpoint being triggered
- Compose the Format by selecting from the various date/time component Pattern drop-down boxes, as well as typing other literals; all the while a Sample text field illustrates what the date and time will look like
- As a comparison to Simple trigger that sends a message at periodic intervals of time, let's create a Cron trigger that does so at particular moments in time. Start by choosing Cron from the Add combo box
- We'll start off with a very simple Cron trigger to fire the top of every minute, that is, at the zeroth second. Appropriately fill in Name, Description and Message fields and then select the Second (1) tab if not already done. Select the Just on Second choice if not already so and the associated spinner to set the second-of-the-minute will be automatically enabled and set this to 0. (Note, the respective controls in the other choices are only enabled if that choice is selected.) This is the only condition that needs to be defined because all the others are already defaulted appropriately (verifiable in the Cron Expression text field (see CronExpression JavaDoc here
) and so you can simply press Add Cron Trigger button
 |
- Although a more complicated Cron Expression generally takes a longer period to run than a demo affords, for illustration sake, let's define one that reminds Americans to vote in the General Election. This is typically the first Tuesday in November every four years, and let's say poll opens at 8:00:00 AM. Start by selecting the Second (1) tab and Just on Second choice, and setting the second spinner to zero (0)
- Set the Just on Minute spinner to 0, Just on Hour spinner to 8, of the Minute (2) and Hour (3) tabs respectively
- Select the Day-of-Week (6) tab and select choice On the and drop down settings First and TUE
- Having done so, the Day (4) tab is automatically set to No specific Day of the month because the Quartz Scheduler API requires it to be mutually exclusive with Day-of-Week
- Select the Month (5) tab and choose Just on Month and month 11 (November)
- Finally, we need to specify the optional Year (7) tab by checking on the option box and then select the Starting on Year choice, setting year to 2008 and the repeating every to 4
- Press Finish and the new Scheduler WSDL editor appears
Create a File WSDL Document
- Similarly, right click over the Process Files folder again, select New | WSDL Document and this time create a FILE Binding Concrete WSDL Document of Type Write and press Next
- Specify the respective fields and click Finish
Create a BPEL and Connect the Components
- Create a new BPEL in the same Process Files folder and drag and drop the Scheduler WSDL to approximately the middle of the Ports column left of the BPEL canvas
- If it appears, OK the ensuing dialog confirming creation of Partner Link to represent the Scheduler BC consuming endpoint
- Similarly, drag and drop the File WSDL to the right column
- Again, if the ensuing dialog appears, click the Swap Roles button since this time the BPEL is the consumer of the service the File BC provides
- Create Receive, Assign, and Invoke activities in the BPEL and Edit the Receive activity to select the Partner Link representing the Scheduler BC
- Press the Create button to create an Input Variable for the Scheduler operation by accepting all the default values in the pop-up dialog (not shown) and hit OK here
- Similarly edit the Invoke activity and also create an Input Variable for the File BC operation
- Double click on the Assign activity to bring up the Mapper and concatentate the FireTriggerOperationIn | Properties | SchedulerBC | Inbound | Trigger Date and FireTriggerOperationIn | schedPart fields and map to part1 of the File input variable, WriteIn, and Save All your work
Deploy a Composite Application for Scheduler BC -> BPEL -> File BC
- Create a new Composite Application project and drag and drop the BPEL project onto the CASA Editor canvas
- Hit the Build (hammer) button twice (second time to get rid of progress label...known issue)
- Right click over the CASA project and select Deploy (you must have a running Glass Fish server with Scheduler Binding Component installed already of course) and you should be getting results in C:\temp\output.xml like this:
12 November 2008 at 3:47:31 PM: Do you need more money Joe?
12 November 2008 at 3:48:00 PM: Top of the Minute to you Hank Paulson, please send more money!
12 November 2008 at 3:48:31 PM: Do you need more money Joe?
12 November 2008 at 3:49:00 PM: Top of the Minute to you Hank Paulson, please send more money!
12 November 2008 at 3:49:31 PM: Do you need more money Joe?
12 November 2008 at 3:50:00 PM: Top of the Minute to you Hank Paulson, please send more money!
Scheduler Binding WSDL Document Syntax
Here's what the above WSDL looks like:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sched="http://schemas.sun.com/jbi/wsdl-extensions/scheduler/"
name="schedEZLoans" targetNamespace="http://j2ee.netbeans.org/wsdl/bpelSubPrimeOrBust/schedEZLoans" xmlns:tns="http://j2ee.netbeans.org/wsdl/bpelSubPrimeOrBust/schedEZLoans" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype">
<wsdl:types>
<xsd:schema targetNamespace="http://schemas.sun.com/jbi/wsdl-extensions/scheduler/">
<xsd:element name="message">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="metadata" minOccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:sequence/>
<xsd:attribute name="date" type="xsd:string" use="required"/>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="group" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="payload" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="TriggerEventMessage">
<wsdl:part name="schedPart" element="sched:message"/>
</wsdl:message>
<wsdl:portType name="TriggerPortType">
<wsdl:operation name="FireTriggerOperation">
<wsdl:input name="inMsg" message="tns:TriggerEventMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TriggerBinding" type="tns:TriggerPortType">
<sched:binding group="schedEZLoans" date-format="dd MMMM yyyy 'at' h:mm:ss a"/>
<wsdl:operation name="FireTriggerOperation">
<sched:operation mode="static"/>
<wsdl:input name="inMsg">
<sched:trigger name="SendLoanApplicationStatus" type="simple" enabled="true" description="Trigger sending loan application status to Joe The Plumber" repeat="indefinite" interval="60000" message="Do you need more money Joe?"/>
<sched:trigger name="AskForBailoutMoney" type="cron" enabled="true" description="Trigger requesting more bailout billions from Feds" cron-expr="0 * * * * ?" message="Top of the Minute to you Hank Paulson, please send more money!"/>
<sched:trigger name="VoteTheScoundrelOut" type="cron" enabled="true" description="Remind Americans to vote to save the economy" cron-expr="0 0 8 ? 11 3#1 2008/4" message="Back away from the remote, get up and go vote!"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TriggerService">
<wsdl:port name="schedEZLoans_TriggerPort" binding="tns:TriggerBinding">
<sched:active-period starting="now" ending="never" timezone="America/Los_Angeles"/>
</wsdl:port>
</wsdl:service>
<plnk:partnerLinkType name="schedEZLoans">
<!-- A partner link type is automatically generated when a new port type is added. Partner link types are used by BPEL processes.
In a BPEL process, a partner link represents the interaction between the BPEL process and a partner service. Each partner link is associated with a partner link type.
A partner link type characterizes the conversational relationship between two services. The partner link type can have one or two roles.-->
<plnk:role name="TriggerPortTypeRole" portType="tns:TriggerPortType"/>
</plnk:partnerLinkType>
</wsdl:definitions>
Systemic Qualities (QoS)
- Please refer to this blog