在《Zeebe Windows 10踩坑记录》系列中,我们创建并发布了流程order-process-new,现在我们用c#程序创建这个流程的实例。创建流程实例需要使用zeebe client的NewCreateWorkflowInstanceCommand方法,我们现在知道流程的名称是order-process-new,我们可以使用下面的方法创建流程实例:
var workflowInstance = await client
.NewCreateWorkflowInstanceCommand()
.BpmnProcessId("order-process-new")
.LatestVersion()
.Variables(WorkflowInstanceVariables)
.Send();
Console.WriteLine(workflowInstance.BpmnProcessId);
Console.WriteLine(workflowInstance.Version);
Console.WriteLine(workflowInstance.WorkflowKey);
Console.WriteLine(workflowInstance.WorkflowInstanceKey);
运行结果如下:
图片.png
如果我们登录到operator中查看,可以看到这个新的实例:
图片.png
如果我们已经知道流程的WorkflowKey,可以使用WorkflowKey创建实例,代码如下:
var workflowInstance = await client
.NewCreateWorkflowInstanceCommand()
.WorkflowKey(2251799813685877)
.Variables(WorkflowInstanceVariables)
.Send();
Console.WriteLine(workflowInstance.BpmnProcessId);
Console.WriteLine(workflowInstance.Version);
Console.WriteLine(workflowInstance.WorkflowKey);
Console.WriteLine(workflowInstance.WorkflowInstanceKey);
运行结果如下:
图片.png