一般情况下,流程的起始节点是None Event类型的,这种类型的流程需要显示创建流程,详见第二讲。如果需要使用消息启动流程,需要将起始节点设置为Message Start Event。我们看下面这个流程:
图片.png
这个流程中,请假人通过界面或者其它方式提交请假申请,这时还没有流程实例,当流程引擎接收到消息后,会创建一个流程实例,并继续执行流程。这部分代码是这样的:
using NLog.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Zeebe.Client;
namespace SendApplyMessage
{
class Program
{
private static readonly string ZeebeUrl = "127.0.0.1:26500";
private static readonly string WorkflowInstanceVariables = "{\"ApplyId\":\"123\",\"Name\":\"张三\",\"Days\":3}";
static async Task Main(string[] args)
{
// create zeebe client
var client = ZeebeClient.Builder()
.UseLoggerFactory(new NLogLoggerFactory())
.UseGatewayAddress(ZeebeUrl)
.UsePlainText()
.Build();
var resp = await client.NewPublishMessageCommand()
.MessageName("Message_Apply")
.CorrelationKey(string.Empty)
.Variables(WorkflowInstanceVariables)
.Send();
Console.WriteLine(resp);
}
}
}