| ESB Service Orchestration with JBPM |
| Written by F.Marchioni | |||||
|
BPM promotes a model-based approach to task definitions: it encourages a top-down approach to service orchestration and requirements. Since the process are defined by the businessmen this should ensure that they drive the business the way they want. In this article we'll see how SOA and BPM are the perfect combination to model your business. One of the key aspects of SOA is Service Orchestration : that is the arrangement of business processes. In this article we'll see how we can achieve this with the combination of JBPM and ESB technologies. JBPM and JBoss ESB can work with each other on both sides: as a matter of fact you can make calls to JBPM environment from the JBoss ESB. You can as well invoke the JBoss ESB services from JBPM: this is what is called service orchestration. Let's see the first communication: JBoss ESB calling JBPMJBossESB can make calls into jBPM using the BpmProcessor class from jboss-esb.xml. The properties NewProcessInstanceCommand - Start a new ProcessInstance StartProcessInstanceCommand - Start a new ProcessInstance and moves it to the first Node CancelProcessInstanceCommand - Cancel a ProcessInstance. Here's an example: <jbossesb> .... <action name="create_new_process_instance" class="org.jboss.soa.esb.services.jbpm.actions.BpmProcessor"> <property name="command" value="StartProcessInstanceCommand" /> <property name="process-definition-name" value="simpleProcess"/> <property name="actor" value="Username"/> <property name="esbToBpmVars"> <mapping esb="eVar1" bpm="counter" default="45" /> <mapping esb="BODY_CONTENT" bpm="theBody" /> </property> </action> </jbossesb>
JBPM invoking ESB services
1) one-way call This way we send information from JBPM to the ESB. How can we do this ? we invoke an action named EsbNotifier when there's a transition from one node to another. <process-definition name="bpm_orchestration"> ... <node name="ShipIt"> <transition name="ProcessingComplete" to="end"> <action name="Action1" class= "org.jboss.soa.esb.services.jbpm.actionhandlers.EsbNotifier"> <esbCategoryName>BPM_Orchestration</esbCategoryName> <esbServiceName>Service1</esbServiceName> <bpmToEsbVars> <mapping bpm="entireCustomerAsObject" esb="customer" /> <mapping bpm="entireOrderAsObject" esb="orderHeader" /> <mapping bpm="entireOrderAsXML" esb="entireOrderAsXML" /> </bpmToEsbVars> </action> </transition> </node>
If you need to return information to your process, then you can use the EsbActionHandler. The EsbActionHandler is attached to the node (and not to the transition!). When this node is entered this action will be called. The EsbActionHandler executes and leaves the node waiting for a transition signal. The signal can come from any other thread of execution, but under normal processing the signal will be send by the JBossESB callback Service <process-definition name="bpm_orchestration"> ... <node name="Intake Order"> <action name="Action1" class= "org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler"> <esbCategoryName>BPM_Orchestration</esbCategoryName> <esbServiceName>CallBackService</esbServiceName> <bpmToEsbVars> <mapping bpm="theBody" esb="BODY_CONTENT" /> </bpmToEsbVars> <esbToBpmVars> <mapping esb="BODY_CONTENT" bpm="theBody"/> </esbToBpmVars> </action> <transition name="" to="Review Order"></transition> </node>
3) Two way communication with timeout When using the EsbActionHandler action it maybe that you want to limit how long you want to wait for. For this scenario you can add a timer to the node. The timer can be set to a certain due date. In this case it is set to 10 seconds. In this scenario if the Service takes over 10 seconds then a transition to the "ExceptionHandling" node takes place. As a matter of fact this is a good practice when something undefined goes wrong (for example the Service is waiting to connect to a remote resource )
<node name="Service1" async="true">
<action class=
"org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
<esbCategoryName>MockCategory</esbCategoryName>
<esbServiceName>MockService</esbServiceName>
</action>
<timer name='timeout' duedate='10 seconds'
transition='time-out-transition'/>
<transition name="ok" to="Service2"></transition>
<transition name="time-out-transition" to="ExceptionHandling"/>
</node>
How do you deal with ESB exceptions ?You can handle exceptions in two ways: the first one is done using the exceptionTransition, the latter with a decision node which checks for error code in JBPM execution context.
<node name="Service1">
<action class=
"org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
<esbCategoryName>ESBCategory</esbCategoryName>
<esbServiceName>ESBService1</esbServiceName>
<exceptionTransition>exception</exceptionTransition>
</action>
<transition name="ok" to="Service2"></transition>
<transition name="exception" to="ExceptionHandling"/>
</node>
Only if the call was made from the EsbActionHandler it makes sense to report back the exception to jBPM. If the call was made from the EsbNotifier jBPM processing has already moved on, and it is of little value to notify the process instance of the exception. This is why the exception-transition can only be specified for EsbAction-Handler. Scenario 2: Exception Decision
<node name="Service3" async="true">
<action class=
"org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
<esbCategoryName>MockCategory</esbCategoryName>
<esbServiceName>MockService</esbServiceName>
<esbToBpmVars>
<mapping esb="SomeExceptionCode" bpm="errorCode"/>
</esbToBpmVars>
</action>
<transition name="ok" to="exceptionDecision"></transition>
</node>
<decision name="exceptionDecision">
<transition name="ok" to="end"></transition>
<transition name="exceptionCondition" to="ExceptionHandling">
<condition>#{ errorCode!=void }</condition>
</transition>
</decision>
|
| Comments |
|






