# 开始事件

消息开始事件,也就是我们通过接收到某些消息后来启动流程实例,比如接收到了一封邮件,一条短信等。
消息开始事件需要由指定的消息触发,由startProcessInstanceByMessage()系列方法提供。

//通过消息名称发起流程实例
runtimeService.startProcessInstanceByMessage(String messageName)
//通过消息名称和业务Key发起流程实例
runtimeService.startProcessInstanceByMessage(String messageName, String businessKey)

//通过消息名称,流程变量发起流程实例
runtimeService.startProcessInstanceByMessage(String messageName, Map<String, Object> params)
//通过消息名称,业务Key, 流程变量发起流程实例
runtimeService.startProcessInstanceByMessage(String messageName, String businessKey,Map<String, Object> params)

# Camunda服务任务发起流程

@Component("handleWarMessage")
@Slf4j
public class HandleWarMessageTask implements JavaDelegate {

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

# Activiti服务任务发起流程

@Component("bookOnlineTask")
@Slf4j
public class BookOnlineTask implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {
        log.info("在线订餐");
        String businessKey = String.valueOf(execution.getVariable("businessKey"));
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
        RuntimeService runtimeService = engine.getRuntimeService();
        runtimeService.startProcessInstanceByMessage("Message_ali_pay", businessKey);
    }
}