View Source

{section}
{column}

h1. Summary

This tutorial explains how you can schedule invocations of Petals services.
Using time policies and a message skeleton, a Petals service can be executed on a regular basis.

\\
Technically, this tutorial shows the creation of a service-unit for the [Petals-SE-Quartz|petalscomponents:Petals-BC-SE-Quartz] component in *consumes* mode.

{info}
*Level:* Easy
*Estimated time:* 10 minutes the first time, 4 minutes then
*Expected skills:* know the basics about WSDL and XML
{info}
{column}
{column:width=350px}
{panel:title=Table of contents}{toc}{panel}
{column}
{section}

h1. Creating the Service-Unit project

h2. Getting started

Start Petals Studio.
In the menu, select *File > New > Petals Service Consumer*.
If you do not see it, go into *File > New > Other...* Then, select *Petals Service Consumer* under the *Petals* category.

\\
A wizard opens, showing three drop-down lists.
In the *Use Case* list, select *Miscellaneaous*.
In the *Petals Component* list, select *Quartz // petals-se-quartz*.
In the *Component Version* list, select the version of the Petals-SE-Quartz that you are using in Petals.

\\
In the scope of this tutorial, we are going to work with the version 1.2 of the Quartz component.
Which gives us:

!petals-studio-tuto-consumes-quartz-1.jpg!

\\
Click *Next*.


h2. Identifying the target service

The current page requires you to fill-in the base information to put in the JBI descriptor (*META-INF/jbi.xml*).
In particular, it defines the interface, service and end-point names of the service that will be invoked regularly.

!petals-studio-tuto-consumes-quartz-2.jpg!

\\
{note}
A service is identified by a triplet, interface, service and end-point names. This triplet is unique in a Petals topology.
When you consume a service, the service is selected in a set. This set is defined by the invocation properties.

If the 3 fields are set in the consume properties, then the set will contain at most 1 result (there can be only 1 service with this ID).
If 2 fields are set, then the third one is considered as a wildcard and the set will larger.

Consume possibilities are the following ones:
* By interface, service and end-point names.
* By interface and service names.
* By interface name only.
{note}

\\
This page also defines the operation to invoke and the Message Exchange Pattern (MEP).
The Message Exchange Pattern (MEP) defines the interactions between the Quartz component and the invoked service.
With this component, only operations that work with the InOnly MEP can be invoked.

\\
You can obviously fill-in these fields by hand.
However, the most efficient way is to use the [Petals Services explorer|Getting familiar with the Petals Services view] (provided it was populated).
Click *Select a service*. A selection dialog shows up, providing filtering assistance.

!petals-studio-tuto-consumes-quartz-2bis.jpg!

\\
When you have selected your service, click *OK*.
The wizard fields are filled-in automatically.

!petals-studio-tuto-consumes-quartz-3.jpg!

\\
{note}
The values for the interface, service and end-point names must match the values defined in the jbi.xml of the invoked service.
Indeed, this service must be a Petals service, and thus be described in a jbi.xml.
As a reminder, the jbi.xml values and the WSDL values (if the WSDL exists) of the invoked service must be exactly the same.

For this reason, filling-in the information by hand or modifying it is discouraged.
{note}

\\
Click *Next*.


h2. Defining the project name

This page defines the name and the location of the project that will be created.
Indeed, this wizard will result in the creation of a project containing all the required elements for a Quartz service-unit.

\\
Enter a project name for your project.
If you do not want your project to be created in the default workspace, uncheck *Use default location*.
Then click *Browse...* and select the location where the project will be created.

!petals-studio-tuto-consumes-quartz-4.jpg!

\\
{note}
Petals service-units have a naming convention.
For a service-unit which consumes (calls) a service, the convention is *su\-*_<Protocol or Technology>_*\-*_<Service name>_*\-consume*
{note}

\\
Then, click *Next*.


h2. Specifying the Quartz parameters

This page defines information which are specific to the Petals Quartz component.
There are only two parameters here:
* The first one is a [CRON expression|http://en.wikipedia.org/wiki/CRON_expression], which defines a time policies used to determine the invocation frequency.
* The second parameter is a static XML message that will be sent to the target service when a time policy triggers an invocation.

The meaning of these parameters can be read in the documentation of the [Petals-SE-Quartz|petalscomponents:Petals-BC-SE-Quartz] component.

\\ !petals-studio-tuto-consumes-quartz-5.jpg!

\\
{note}
The current tooling is very basic for this component.
There is neither an editor for CRON expressions, nor generation facilities for the XML message.
{note}

{tip}
You can use SoapUI to generate a skeleton of XML message for the target service.
For this, you only need the WSDL definition of the invoked service. SoapUI will do the rest.
{tip}

{note}
The XML message must be valid with respect to the WSDL of the target service.
It must respect the XML schemas associated with the input message of the invoked operation.
{note}

\\
Click *Finish* to complete the wizard.


h2. Checking the result

When the wizard has completed, a new project has been created and is visible in your workspace.

It contains a jbi.xml file, located under *src/main/jbi*.
This hierarchy allows you to work with Apache Maven then (a pom.xml was also created at the root of the project).
There is nothing else in the project.

\\ !petals-studio-tuto-consumes-quartz-7.jpg!


h1. Updating, packaging and deploying

h2. Further edition and packaging

After completion, the newly created jbi.xml file has been open in the Service-Unit editor.
Regarding Quartz configurations, the wizards are complete and provide all the options.
Thus, you do not need to edit the jbi.xml.

However, if you need to update it manually, be careful: the XML message must be contained in a CDATA section.
Here is a sample configuration of the Quartz component.

{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBI descriptor for the Petals' "petals-se-quartz" component (Quartz).
Originally created for the version 1.1 of the component.
-->
<jbi:jbi version="1.0"
xmlns:generatedNs="http://petals.ow2.org/components/hl7/version-1"
xmlns:jbi="http://java.sun.com/xml/ns/jbi"
xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5"
xmlns:quartz="http://petals.ow2.org/components/quartz/version-1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<!-- Import a Service into Petals or Expose a Petals Service => use a BC. -->
<jbi:services binding-component="false">

<!-- Expose a Petals Service => consumes a Service. -->
<jbi:consumes
interface-name="generatedNs:PetalsHl7PortType"
service-name="generatedNs:PetalsHl7Service"
endpoint-name="PetalsHl7ServicePort">

<!-- CDK specific elements -->
<petalsCDK:timeout>30000</petalsCDK:timeout>
<petalsCDK:operation xmlns:sendInOnlyNs="http://petals.ow2.org/components/hl7/version-1">sendInOnlyNs:sendInOnly</petalsCDK:operation>
<petalsCDK:mep>InOnly</petalsCDK:mep>

<!-- Component specific elements -->
<quartz:cron-expression>0 0 12 * * ? </quartz:cron-expression>
<quartz:content><![CDATA[<!-- Put the XML message to send here -->
<text>hello</text>]]></quartz:content>
</jbi:consumes>
</jbi:services>
</jbi:jbi>
{code}

\\
The project contains everything the Quartz component needs.
You can now package it before deploying it.

\\
The created project being a [Service-Unit project|Working with Service Unit projects], you can [package it as any Service-Unit project|Working with Service Unit projects#Export for Petals].
It results in the creation of a Service Assembly for the Petals-SE-Quartz component. Its location depends on your export choices.

h2. Deployment

The deployment of the created service assembly can be achieved with the Petals web console.
Or you can do it by dropping the service assembly in the *install* directory of your Petals installation.
This second option should only be used in development steps.

\\
First, make sure the Petals-SE-Quartz is installed in your Petals environment.
Then, install the service assembly in your Petals, using one of the two ways indicated above.

\\
There is no need to update configuration of the Quartz component to make it work.
Using the default settings is enough to make the service-unit work.