Sample Guide - Pick

Objective

<pick/> can be used for event based execution. Inside <pick/>, we can define activities to be executed when there is an event or a set of events occur. These events can be defined in <onMessage/> or <onAlarm/>. <onMessage/> is used to define events based on arrival of a message. <onAlarm/> is used to define events based on specific time point or time interval. <pick/> activity should include at least one <onMessage/> element while <onAlarm/> is optional. Additionally user have to define a correlation set and refer it in each event in-order to determine the correct execution path.

eg - Let's take PickProcess.bpel in TestPickOneWay.zip (sample is located at our sample repository.)

This bpel process can be invoked by 5 operations. Those operations are dealDeck, pickSpade, pickClub, pickHeart and pickDiamond.

eg -

  • <receive operation="dealDeck" partnerLink="IncomingLink" variable="deckRequest" createInstance="yes" .../>
  • <onMessage operation="pickSpade" partnerLink="IncomingLink" variable="spadeRequest" .../>
  • <onMessage operation="pickClub" partnerLink="IncomingLink" variable="clubRequest" .../>
  • <onMessage operation="pickHeart" partnerLink="IncomingLink" variable="heartRequest" .../>
  • <onMessage operation="pickDiamond" partnerLink="IncomingLink" variable="diamondRequest" .../>

So once one of these operations is executed, the bpel process is invoked. But only "dealDeck" operation can create an instance of this process as its createInstance attribute is set to "yes". If one of the other operations are executed, a job will be queued until an instance is created. So once an instance is created, the queued job will be triggered.


Prerequisites

  • Log in into BPS server admin console.
  • Under Business Processes -> Add BPEL.
  • Upload the TestPickOneWay.zip , (all samples are located at our sample repository.)
  • Under the Business Processes -> Processes.
  • Under the WSDL details widget -> Create instance

Overall Idea

refer TestPickOneWay.zip

  • Defining correlation set.
    <correlationSets>
        <correlationSet name="CorrelationByDeck" properties="srvns:deck"/>
    </correlationSets>
    

    This property is defined at PickService.wsdl as follows.

    <vprop:property name="deck" type="xsd:token"/>
    <vprop:propertyAlias messageType="tns:dealDeckRequest" part="parameters" propertyName="tns:deck">
        <vprop:query>tns:Deck</vprop:query>
    </vprop:propertyAlias>
    

    Here the property points to a particular message element which is called <Deck/> in the dealDeckRequest message type.

    eg -

    <dealDeck>
        <Deck></Deck>
    </dealDeck>
    
  • So once a message of the type dealDeckRequest is received, an instance of correlation set will be created based on the value of the element <Deck/>.
  • In this sample, when a dealDeckRequest message is received a process instance is created due tocreateInstance="yes". As well a correlation set instance is also created due toinitiate="yes".
    <receive operation="dealDeck" partnerLink="IncomingLink" variable="deckRequest"
             createInstance="yes">
        <correlations>
            <correlation initiate="yes" set="CorrelationByDeck"/>
        </correlations>
    </receive>
    
  • Suppose there's a incoming message for a operation defined in <onMessage>. So once the message is received to the process, it'll be verified with correlation set instance. If there's an existing process instance, which is compliant with the correlation set instance, then the instance will execute the particular set of activities defined.
  • If the incoming message's operation is "pickSpade", and the partnerLink is "IncomingLink" , and the incoming message is compliant with the correlation set instance of the process instance, following activities are executed.
    <onMessage operation="pickSpade" partnerLink="IncomingLink" variable="spadeRequest">
        <correlations>
            <correlation initiate="no" set="CorrelationByDeck"/>
        </correlations>
        <sequence>
            <assign>
                <copy>
                    <from>
                        <literal>
                            <pickSpadeResponse xmlns="http://www.stark.com/PickService">
                                <Deck/>
                            </pickSpadeResponse>
                        </literal>
                    </from>
                    <to variable="spadeResponse" part="parameters"/>
                </copy>
                <copy>
                    <from>bpel:getVariableProperty("spadeRequest", "srvns:deck")</from>
                    <to>$spadeResponse.parameters/srvns:Deck</to>
                </copy>
            </assign>
            <reply operation="pickSpade" partnerLink="IncomingLink" variable="spadeResponse"/>
        </sequence>
    </onMessage>