简体   繁体   English

Activiti-如何同步用户任务

[英]Activiti - How to synchronize a User Task

I have an Activiti flow that has a User Task section, that looks like this: 我有一个具有用户任务部分的Activiti流,如下所示:

流屏

The basic idea is that the "Wait for Notification" user task, waits for a response from special Queue. 基本思想是“等待通知”用户任务等待特殊队列的响应。 But actualy a specific code just compets the task: 但是实际上,一个特定的代码只是完成任务:

Map<String, Object> variables = new HashMap<String, Object>();
variables.put("KEY", variable);

String assignee = variable.getAssignee();
processService.completeTask(assignee, variables);

So my problem is that the service responsible for this code can receive several responses form that queue. 所以我的问题是,负责此代码的服务可以从该队列接收几个响应。 Which is the kind of behavior I want (the Queue, can return something like Message_Processed and after a few milliseconds return Message_Send). 这是我想要的行为(队列可以返回类似Message_Processed的内容,并在几毫秒后返回Message_Send)。 But when the second response comes the Activiti Engine throws an Exception (see cause), and the whole flow dies. 但是,当第二个响应到来时,Activiti Engine会引发Exception(请参阅原因),并且整个流程都会终止。

Caused by: org.activiti.engine.ActivitiOptimisticLockingException: Task[id=3867, name=Wait for Notification] was updated by another transaction concurrently

So what I'm looking for: Is there a way to make a task, somehow that it will take and swallow all responses not throwing an Exception. 所以我要寻找的是:有没有一种方法可以执行任务,它将以某种方式吞并所有响应而不抛出异常。

I see the following points: 我看到以下几点:

1) You might want to check out the Activiti Receive Task. 1)您可能想签出Activiti接收任务。 This is actually a better fit to wait until a signal to proceed arrives: http://www.activiti.org/userguide/index.html#bpmnReceiveTask 实际上,这更适合等待信号继续到达: http : //www.activiti.org/userguide/index.html#bpmnReceiveTask

2) You probably receive the OptimisticLockingException because your updates come along "too fast" and concurrently. 2)您可能会收到OptimisticLockingException,因为您的更新“太快”并发了。 Here I see the options 在这里我看到了选项

  • that you configure your queue consumer in a way so that it can receive messages from the queue just in a single threaded exclusive manner. 您以某种方式配置队列使用者,以便它可以以单线程互斥方式从队列接收消息。 You should then also make sure that your subsequent "Update MessageVO" service task as well as your receive task is not marked to be async=true. 然后,您还应确保后续的“ Update MessageVO”服务任务以及接收任务标记为async = true。 This will make sure that you will signal the receive task to proceed and within the same database transaction create a new receive task again ready to be updated by the next message. 这将确保您将发出接收任务的信号,并在同一数据库事务中创建一个新的接收任务,再次准备由下一条消息进行更新。

  • that you let the queue consumer "crash" with the optimistic locking exception and make sure that your transacted session with the queue producer is rolled back or explicitely asking for redelivery so that the message gets redelivered according to some redelivery policy. 确保您使用乐观锁定异常让队列使用者“崩溃”,并确保您与队列生产者的事务处理会话已回滚或明确要求重新交付,以便根据某些重新交付策略重新传递消息。

3) Another reason for your OptimisticLockingException might be that you cache the old/updated task instead of querying for it immediately before signalling to proceed. 3)OptimisticLockingException的另一个原因可能是您缓存了旧的/更新的任务,而不是在发出信号之前立即查询它。 always do that so that you don't "reuse" any outdated task or execution object 始终这样做,以免“重用”任何过时的任务或执行对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM