《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
processDefinitionKey启动,代码如下:
@Test
@org.activiti.engine.test.Deployment(resources = “my-process.bpmn20.xml”)
public void testStartProcessInstanceByKey() {
RuntimeService runtimeService = activitiRule.getRuntimeService();
Map<String, Object> map = Maps.newHashMap();
map.put(“name”, “zhangxingr”);
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,流程定义文件如下:
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);
}
ProcessInstanceHelper processInstanceHelper = commandContext.getProcessEngineConfiguration().getProcessInstanceHelper();
总结
虽然我个人也经常自嘲,十年之后要去成为外卖专员,但实际上依靠自身的努力,是能够减少三十五岁之后的焦虑的,毕竟好的架构师并不多。
架构师,是我们大部分技术人的职业目标,一名好的架构师来源于机遇(公司)、个人努力(吃得苦、肯钻研)、天分(真的热爱)的三者协作的结果,实践+机遇+努力才能助你成为优秀的架构师。
如果你也想成为一名好的架构师,那或许这份Java成长笔记你需要阅读阅读,希望能够对你的职业发展有所帮助。
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
+努力才能助你成为优秀的架构师。
如果你也想成为一名好的架构师,那或许这份Java成长笔记你需要阅读阅读,希望能够对你的职业发展有所帮助。
[外链图片转存中…(img-16OoYfBk-1714409157528)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!