2017-04-19 1075 views
2

根据Camunda的文档(https://docs.camunda.org/manual/latest/user-guide/process-applications/process-application-event-listeners/),可将“全局”事件处理程序(ExecutionListener或TaskListener)添加到ProcessApplication

尽管如此,我还是无法在运行时找到添加类似(“全局”)事件处理程序的方法。此功能在Activiti中使用引擎的(https://www.activiti.org/javadocs/org/activiti/engine/RuntimeService.html#addEventListener-org.activiti.engine.delegate.event.ActivitiEventListener-)的方法addEventListener存在,但Camunda的RuntimeService中不再存在。

如何在运行时添加“全局”事件处理程序?
注意:事件处理程序将被添加到的ProcessApplication不能被修改,因为我想从不同的库中添加处理程序。

谢谢大家,Camunda在运行时添加事件处理程序(ExecutionListener或TaskListener)

回答

3

社区延伸camunda-bpm-reactor允许您登记propgates事件的每一个听众将被触发时间eventbus。然后您可以在这些事件上注册侦听器。所以bpmn和监听器代码在运行时耦合在一起。

@CamundaSelector(type = "userTask", event = TaskListener.EVENTNAME_CREATE) 
public class TaskCreateListener implements TaskListener { 

    public TaskCreateListener(EventBus eventBus) { 
    eventBus.register(this); 
    } 

    @Override 
    public void notify(DelegateTask delegateTask) { 
     ... 
    } 
} 
+0

太棒了!正是我需要的 –

2

我认为Activiti的方法addEventListener加入Camunda分叉的Activiti后,这就是为什么该方法不适用于Camunda的RuntimeService。

正如文档所述,您可以定义一个返回全局执行/任务侦听器的进程应用程序。要在运行时定义流程应用程序,您可以使用EmbeddedProcessApplicationManagementService#registerProcessApplication方法。

见下面的例子:

EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() { 
    public ExecutionListener getExecutionListener() { 
    return new ExecutionListener() { 
     public void notify(DelegateExecution execution) throws Exception { 
     // do your stuff  
     }    
    }; 
    } 
}; 

// register app so that it is notified about events 
managementService.registerProcessApplication(deploymentId, processApplication.getReference()); 
+0

但是,如果流程应用程序已经被定义和初始化了,我该怎么办?我可以修改processApplication以添加处理程序吗?我想添加从库的处理程序到现有的应用程序... –

相关问题