- Before an activity.
- Asynchronous process instantiation using the async start event. (Added in 7.0).
With camunda BPM 7.2.0-alpha3, Asynchronous continuations become even more powerful:
- You can now place an asynchronous continuation AFTER an activity. (HOT!)
- Asynchronous continuations are now supported on more BPMN 2.0 constructs, such as the Parallel Gateway.
Why Asynchronous Continuations?
- Async is used for placing a safe-point before an activity such that the execution state is committed. If the activity then fails to execute, the transaction is rolled back only up to the safe point.
- Async also comes in handy if you have longer-running computations and do not want to block the calling thread (eg. HTTP Thread) but instead want to delegate the heavy lifting to a background thread.
- Finally, due to the fact that asynchronous continuations are executed by the job executor, the retry mechanism can be used in order to retry a failed activity execution.
More in-depth information about how asynchronous continuations work in camunda BPM can be found in the userguide.
Asynchronous Continuations After an Activity
<!-- AFTER (new) --> <serviceTask id="service1" name="Generate Invoice" camunda:asyncAfter="true" camunda:class="my.custom.Delegate" /> <!-- BEFORE --> <serviceTask id="service1" name="Generate Invoice" camunda:asyncBefore="true" camunda:class="my.custom.Delegate" />
Asynchronous continuations after an activity are useful if you want to make sure that the state changes performed by the activity are saved before the process engine continues process execution.
- Usually this is a lot more intuitive than placing the asynchronous continuation before the next activity.
- An activity may have multiple outgoing sequence flows. Without the capability to place an asynchronous continuation after the activity, you would have to place it before all of the next activities.
- Not every activity may have a “next activity”. In BPMN 2.0 it is perfectly valid that an activity does not have any outgoing flows. Or, the activity may be a compensation handler which is not allowed to have an outgoing sequence flow.
- If the activity is followed by a synchronizing construct (like a parallel gateway) it is useful to place a safe point after the activity in order to make sure a potential failure & retry caused by optimistic locking does not affect the activity. (You could also place an asynchronous continuation BEFORE the parallel gateway, of course).
I think that currently camunda BPM is the most advanced open source process engine in this area. If you know another open source process engine with has more flexible asynchronous continuation capabilities, let us know, I am always good for a challenge 🙂
As a side-note: the concept which makes asynchronous continuations possible is the “Atomic Operation”. When the process engine executes a process, it will progress though the graph as a sequence of Atomic Operations. It then becomes possible to break execution between two atomic operations being executed. We are implementing CMMN (The new standard for adaptive case management, ACM) with the same programming model. As a result, it will also be possible to implement Async for CMMN as well 🙂
Camunda Developer Community
Join Camunda’s global community of developers sharing code, advice, and meaningful experiences