Java教程

Activiti 流程启动的几种方式,java架构师指南网盘下载

本文主要是介绍Activiti 流程启动的几种方式,java架构师指南网盘下载,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

map.put(“sex”, “man”);

map.put(“age”, “21”);

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(“my-process”, map);

logger.info(“processInstance = {}”, processInstance);

}

2、processDefinitionId启动

@Test

@org.activiti.engine.test.Deployment(resources = “my-process.bpmn20.xml”)

public void testStartProcessInstanceById() {

RuntimeService runtimeService = activitiRule.getRuntimeService();

Map<String, Object> map = Maps.newHashMap();

map.put(“name”, “zhangxingr”);

map.put(“sex”, “man”);

map.put(“age”, “21”);

ProcessDefinition processDefinition = activitiRule.getRepositoryService()

.createProcessDefinitionQuery().singleResult();

ProcessInstance processInstance = runtimeService

.startProcessInstanceById(processDefinition.getId(), map);

logger.info(“processInstance = {}, process’key = {}, process’name = {}”,

processInstance, processInstance.getProcessDefinitionKey(),

processInstance.getName());

}

3、message启动

根据message启动就要复杂一些,需要改动一下流程定义文件的startEvent,增加messageEventDefinition,流程定义文件如下:

<process id="my-pro

【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】

浏览器打开:qq.cn.hn/FTf 免费领取

cess">

message启动,代码如下:

@Test

@org.activiti.engine.test.Deployment(resources = “my-process-message.bpmn20.xml”)

public void testMessageStart() {

RuntimeService runtimeService = activitiRule.getRuntimeService();

ProcessInstance processInstance = runtimeService

.startProcessInstanceByMessage(“my-message”);

logger.info(“processInstance = {}”, processInstance);

}

根据message启动底层源码实现最终其实还是会走到用processDefinitionId来启动来,所以建议直接使用processDefinitionId方式启动,底层代码如下:

public ProcessInstance execute(CommandContext commandContext) {

if (messageName == null) {

throw new ActivitiIllegalArgumentException(“Cannot start process instance by message: message name is null”);

}

MessageEventSubscriptionEntity messageEventSubscription = commandContext.getEventSubscriptionEntityManager().findMessageStartEventSubscriptionByName(messageName, tenantId);

if (messageEventSubscription == null) {

throw new ActivitiObjectNotFoundException(“Cannot start process instance by message: no subscription to message with name '” + messageName + “’ found.”, MessageEventSubscriptionEntity.class);

}

String processDefinitionId = messageEventSubscription.getConfiguration();

if (processDefinitionId == null) {

throw new ActivitiException(“Cannot start process instance by message: subscription to message with name '” + messageName + “’ is not a message start event.”);

}

DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();

ProcessDefinition processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);

if (processDefinition == null) {

throw new ActivitiObjectNotFoundException(“No process definition found for id '” + processDefinitionId + “’”, ProcessDefinition.class);

}

这篇关于Activiti 流程启动的几种方式,java架构师指南网盘下载的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!