如何为BPMN2 Exclusive Gateway设置条件

Jan*_*ert 4 java spring bpmn camunda

我在我的春季项目中第一次使用Camunda BPMN2并尝试了解我的一些事情......

在我的applicationContext中,我有以下块来设置Camunda:

    <!-- Setup BPMN Process Engine -->
    <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">
        <property name="processEngineName" value="engine" />
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="jobExecutorActivate" value="false" />
        <property name="deploymentResources" value="classpath*:*.bpmn" />
    </bean>
    <bean id="processEngine" class="org.camunda.bpm.engine.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
    <context:annotation-config />
Run Code Online (Sandbox Code Playgroud)

我已经设置了两项服务:

@Component(value="service1")
public class Service1 implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {     
        System.out.println(">>>>>>>>>>>>>>>>>>>");
        System.out.println("SERVICE1");     
        System.out.println(">>>>>>>>>>>>>>>>>>>");      
    }
}
Run Code Online (Sandbox Code Playgroud)

@Component(value="service2")
public class Service2 implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println(">>>>>>>>>>>>>>>>>>>");
        System.out.println("SERVICE2");     
        System.out.println(">>>>>>>>>>>>>>>>>>>");
    }
}
Run Code Online (Sandbox Code Playgroud)

在方案1中,我有一个并行网关,它同时调用Service1和Service2(我在eclipse中使用BPMN2编辑器构建了这些图表):

方案1

方案1  - 服务1

方案1  - 服务2

运行这行代码:

runtimeService.startProcessInstanceByKey("ConnectorSwitch");
Run Code Online (Sandbox Code Playgroud)

打印出来

>>>>>>>>>>>>>>>>>>>
SERVICE1
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
SERVICE2
>>>>>>>>>>>>>>>>>>>
Run Code Online (Sandbox Code Playgroud)

正如所料.

现在我正试图建立一个独家网关:

在此输入图像描述

运行它给了我以下例外:

SEVERE: Error while closing command context                                                                                                                                                                                                 
org.camunda.bpm.engine.ProcessEngineException: Exclusive Gateway 'ExclusiveGateway_3' has outgoing sequence flow 'SequenceFlow_39' without condition which is not the default flow. | ..../ConnectorSwitch.bpmn | line 0 | column 0                                                                                                                                                                                                              
Exclusive Gateway 'ExclusiveGateway_3' has outgoing sequence flow 'SequenceFlow_40' without condition which is not the default flow. | ..../ConnectorSwitch.bpmn | line 0 | column 0                 

        at org.camunda.bpm.engine.impl.util.xml.Parse.throwExceptionForErrors(Parse.java:183)
        at org.camunda.bpm.engine.impl.bpmn.parser.BpmnParse.execute(BpmnParse.java:177)     
        at org.camunda.bpm.engine.impl.bpmn.deployer.BpmnDeployer.deploy(BpmnDeployer.java:106)
        at org.camunda.bpm.engine.impl.persistence.deploy.DeploymentCache.deploy(DeploymentCache.java:50)
        at org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager.insertDeployment(DeploymentManager.java:42)
        at org.camunda.bpm.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:81)                                        
        at org.camunda.bpm.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:50)                                        
        at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)            
        at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:90)
        at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) 
    ......
Run Code Online (Sandbox Code Playgroud)

异常非常清楚,我在专属网关上缺少一个条件.所以我的问题是,我如何为独占网关分配一个条件,如何调用某个类中的方法并评估true/false,如果我想调用其他不是service1/service2的JavaDelegate的东西(换句话说,MyClass.doSomethingWithParams(someparam)),我该怎么做呢?

XML中的答案也很好,更愿意学习如何在XML中使用BPMN2而不是依赖BPMN2视觉效果.

Mar*_*mak 12

Camunda Modeler中,单击来自专用网关的其中一个序列流.然后选择Properties窗格和General子窗格.您将看到一个属性Condition.此属性可以使用JUEL表达式填充,就像您用于委托的表达式一样.你可以在那里使用你的Spring bean,例如在它们上面调用一个方法.所以如果myClass是一个Spring bean名称,那就写吧${myClass.doSomethingWithParams(someparam)}.或者,您可以访问已附加到流程实例的流程变量.someparam可能是这样一个变量,例如 - >只要确保所有传出的序列流都附加了这样的条件.然后您的流程将再次运行.也许先从像${true}和的简单条件开始${false}.如果这样可行,继续前进并做一些更复杂的事情.玩得开心!:-)

  • 非常欢迎您在(几乎总是)有用的camunda用户社区中受到欢迎.:-) (2认同)