Search code examples
oracleasynchronoussynchronousbpel

Best practice when calling async bpel process from sync bpel process


I have a sync process that waits, by polling a database, for an async process to respond. Basically the async process inserts a new record into a database, and the sync process checks periodically for an update to it, continuing its execution after an update is found. The async process is not invoked by the sync one.

I'm believing that this isn't the only solution available, concerning a sync process waiting for an async one. My question here is, is there any better way to do it? Concerning performance specially.

If there's already an answer to this question, i'm sorry, but i haven't found it.


Solution

  • A better way would be to send a message from the async process to the sync one. The latter could just block with a receive activity until the message arrives. This is better from a performance viewpoint, because the sync process does not have to wake up regularily and check the database. Instead, it could just sleep until the engine detects the arrival of the message and wakes up the sync process.

    Please note that this implies that you have to use correlationSets [1] on the side of the sync process, which have to be initiated some point in time before waiting on the actual message (for instance during your initial receive). This is needed so that the engine can decide to which process instance to forward the message to. You also might want to add an additional partnerLink with myRole to the sync process so that there is an operation to invoke by the async process (which then also needs a corresponding partnerLink). The structure of the sync process which I mean looks somehow like this:

    <sequence>
      <receive name="initialSyncReceive" createInstance="yes" partnerLink="originalPartnerLink" ... />
      <!-- some logic before waiting on async process -->
      <receive name="notificationFromAsync" partnerLink="newPartnerLinkForAsyncOnly" ... />
      <!-- some logic after notification from async process -->
      <reply name="replyToSyncRequest" partnerLink="originalPartnerLink" ... />
    <sequence>
    

    Disclaimer: This is just an outline and you cannot just copy/paste the code. Getting this scenario to work requires a number of non-trivial changes to both processes, e.g. adding correlationSets, additional WSDLs, propertyAliases, and partnerlinks.