27.2. 执行批准过程的请求示例
创建有效进程定义实例后,您可以使用公共和内部 KIE API 的组合来执行它。要执行进程,请创建一个资源
,用于创建 KieBase
。通过使用 KieBase
,您可以创建一个 KieSession
来执行进程。
以下示例使用 ProcessBuilderFactory.toBytes
进程来创建 ByteArrayResource
资源。
执行进程的请求示例
// Build resource from Process KieResources resources = ServiceRegistry.getInstance().get(KieResources.class); Resource res = resources .newByteArrayResource(factory.toBytes(process)) .setSourcePath("/tmp/processFactory.bpmn2"); // source path or target path must be set to be added into kbase // Build kie base from this resource using KIE API KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); KieFileSystem kfs = ks.newKieFileSystem(); kfs.write(res); KieBuilder kb = ks.newKieBuilder(kfs); kb.buildAll(); // kieModule is automatically deployed to KieRepository if successfully built. KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId()); KieBase kbase = kContainer.getKieBase(); // Create kie session using KieBase KieSessionConfiguration conf = ...; Environment env = ....; KieSession ksession = kbase.newKieSession(conf,env); // execute process using same process Id that is used to obtain ProcessBuilder instance ksession.startProcess(processId)