Monday, April 26, 2010

Difference between a Pick activity and a Receive activity

It is a very common query among people that why we go for Pick activity when we already have a receive activity with us.

Through Pick activity you can specify that the business process should await the occurrence of one event in a set of events. Events can be message events handled with the activity or alarm events handled with the activity. For each event, you specify an activity or a set of activities that should be performed.

The syntax of the activity looks like this:

<pick>

<onMessage partnerLink="name"
portType="name"
operation="name"
variable="name">

<!-- Perform an activity or a set of activities enclosed by
<sequence>, <flow>, etc. or throw a fault -->
</onMessage>

<onMessage ...>
<!-- Perform an activity -->
</onMessage>

...

<onAlarm ...>
<!-- Perform an activity -->
</onAlarm>

...

</pick>


Within Pick activity you can specify several onMessage block and several onAlarm block which are optional.

The OnMessage element In Pick Activity is identical to the receive activity and has the same set of attributes. You must specify the following attributes:

1>partnerLink: Specifies which partner link will be used for the invoke, receive, or reply.
2>portType: Specifies the used port type
3>operation: Specifies the name of the operation whose invocation to wait for
4>variable: Specifies the variable name used to store the incoming message

Using the onAlarm element, you can specify a

1>Duration expression, using a for attribute
2>Deadline expression, using an until attribute


So the best part is that you can have multiple onMessage activity which can wait for similar partner link and port type but for different operations so separate threads and parallel processes can be invoked for each operation.

The other important point about Pick activity is that it can be used as a event handler.It can be used in a scenario where in you are calling a asynchronous process and you want your process to complete without waiting for the output.But again we can define event handler in that case that is using pick activity in a scope which can deal with the flow when the message or the response arrives at the bpel process.

You can specify event handlers for the whole BPEL process or for each scope. Event handlers are specified immediately after the compensation handlers and before the main activity, as shown below:

<process ...>

<partnerLinks>
...
</partnerLinks>

<variables>
...
</variables>

<faultHandlers>
...
</faultHandlers>

<compensationHandler>
...
</compensationHandler>

<eventHandlers>

<onMessage ...>
<!-- Perform an activity -->
</onMessage>
...

<onAlarm ...>
<!-- Perform an activity -->
</onAlarm>
...

</eventHandlers>

activity
</process>

The syntax of the event handler is similar to the syntax of the pick activity. The only difference is that in event handler, you can specify zero or more onMessage events and zero or more onAlarm events.

No comments: