在JavaDelegate中使用runtimeService服务

背景

在工作流服务任务中,常需要使用RuntimeService接口用于发起流程等业务。Camunda,Activit,Flowable三款产品在这个场景上操作有所不同, 现总结如下。

JeecgFlow 在线体验

camunda

java 复制代码
@Component("handleWarMessage")
@Slf4j
public class HandleWarMessageTask implements JavaDelegate {

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        RuntimeService runtimeService = delegateExecution.getProcessEngine().getRuntimeService();
        runtimeService.startProcessInstanceByMessage("Message_war");
    }
}

可以通过这种方式访问所有camunda服务的API。

java 复制代码
@Component("handleWarMessage")
@Slf4j
public class HandleWarMessageTask implements JavaDelegate {

    @Autowired
    private RuntimeService runtimeService;

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        runtimeService.startProcessInstanceByMessage("Message_war");
    }
}

这是通过注入获取RuntimeService服务,与前面代码功能相同。

::: warning

需要注意,由于服务调用时当前事务中完成的, 所以在执行服务任务之前产生或修改的数据尚未存入数据库。

这是因为所有API调用都基于数据库数据处理,这些未提交的更改在服务任务API中调用不可见。

:::

Activiti

java 复制代码
@Component("handleWarMessage")
@Slf4j
public class HandleWarMessageTask implements JavaDelegate {

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        RuntimeService runtimeService = Context.getProcessEngineConfiguration().getRuntimeService();\
        runtimeService.startProcessInstanceByMessage("myKey");
    }
}

可以通过这种方式访问所有Activiti服务的API。

java 复制代码
@Component("handleWarMessage")
@Slf4j
public class HandleWarMessageTask implements JavaDelegate {
    @Autowired
    private RuntimeService runtimeService;

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        runtimeService.startProcessInstanceByMessage("myKey");
    }
}

这是通过注入获取RuntimeService服务,与前面代码功能相同。

::: warning

需要注意,由于服务调用时当前事务中完成的, 所以在执行服务任务之前产生或修改的数据尚未存入数据库。

这是因为所有API调用都基于数据库数据处理,这些未提交的更改在服务任务API中调用不可见。

:::

Flowable

java 复制代码
@Component("handleWarMessage")
@Slf4j
public class HandleWarMessageTask implements JavaDelegate {

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        RuntimeService runtimeService = Context.getProcessEngineConfiguration().getRuntimeService();\
        runtimeService.startProcessInstanceByMessage("myKey");
    }
}

可以通过这种方式访问所有Activiti服务的API。

java 复制代码
@Component("handleWarMessage")
@Slf4j
public class HandleWarMessageTask implements JavaDelegate {
    @Autowired
    private RuntimeService runtimeService;

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        runtimeService.startProcessInstanceByMessage("myKey");
    }
}

这是通过注入获取RuntimeService服务,与前面代码功能相同。

相关推荐
catino3 天前
Activiti详解
activiti·工作流引擎
RuoyiOffice3 天前
UniApp企业办公:把审批、客户和项目装进手机,能做些什么?
spring boot·vue3·uniapp·crm·flowable·移动办公·企业应用
RuoyiOffice4 天前
SpringBoot OA推荐:面向信创选型,看看这套企业协同平台
spring boot·vue3·信创·flowable·企业协同·ruoyi office·oa选型
RuoyiOffice6 天前
Flowable 状态通知设计:单体用本地事件,微服务如何回写业务状态?
spring boot·微服务·vue3·flowable·ruoyi office·redis stream·流程状态通知
RuoyiOffice7 天前
项目预算和交付日期变了,为什么不能直接改台账?
spring boot·项目管理·vue3·flowable·业务建模·ruoyi office·项目变更
RuoyiOffice8 天前
SpringBoot+Vue3 单据校验设计:保存草稿、提交审批、退回重填,各该检查什么?
spring boot·vue3·flowable·表单设计·ruoyi office·草稿保存·单据校验
Mark_ZP24 天前
Camunda修改列表
camunda
RuoyiOffice1 个月前
SpringBoot3+Vue3 低代码业务表单:从拖拽设计、独立建表到审批与数据查询
spring boot·vue3·数据建模·flowable·版本管理·低代码表单·ruoyi office
大龄码农有梦想1 个月前
企业工作流系统如何设计用户、部门、角色、岗位、动态关系五类流程办理人?
工作流引擎·flowable·流程引擎·oa·工作流系统·选人规则·bpm平台
李少兄1 个月前
解决Activiti排他网关(ExclusiveGateway)陷入无限死循环问题
activiti