Throwing exceptions from JBPM WorkItemHandlers?

回眸只為那壹抹淺笑 提交于 2019-12-06 11:43:51

Essentially you are asking two questions which we can address separately, and let's see if we can address your concerns:

  1. What is the best-practice way to handle exceptions thrown by work item handlers?

There is no silver bullet here. It depends on many different factors such as:

  • Can you recover from the exception? For example, if jBPM and the resource you access in the WorkItemHandler respect the same XA transaction and the exception in question marked the transaction for rollback, your options are limited as the persistent state won't be stored.

  • If you can recover, what do you want to do? Retry, intervene manually, abort the process and log the failure, or reverse previous activities in a compensation flow?

  • Based on what you want to do, where is the best place to do it? Java or BPMN? BPMN is good for compensation, but a WorkItemHandler or perhaps a Decorator may be better for retries. Maybe it is a combination of the two and you convert a Java Exception to a BPMN Signal/Error that indicates to the caller it should retry.

There is no single answer here and many different approaches could be valid.

  1. Is the Magnolia method something that's deprecated, or that works only by accident? Or is it something that I can count on continuing to work?

Nope, not deprecated, and looking at the code I'd say it works by design. Just keep in mind that in their example you are using Magnolia's decorators, in which case you should ask the Magnolia guys whether they will support it in future. But there are many examples of decorators and you are free to write some yourself to implement the exception handling technique(s) you choose.

In jBPM 6.2, you can use an Error boundary event which you can "attach" to a specific task. So for example, if inside your Evaluation task you are throwing a java.lang.ArithmeticException, you can use this boundary event to catch the exception and have it go to another task to handle the exception.

Correct me if this is incorrect, but I think the boundary exception handling is asynchrounous with the execution of the task which threw the error.

You can try something like the following:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!