在Operator中,我们可以看到新创建的三个流程都停留在第一个环节,没有继续执行:
图片.png
这是因为我们没有启动这些环节相关的服务,在服务没有完成前,流程不继续执行。我们在《Zeebe Windows 10踩坑记录》中使用控制台命令创建了模拟服务,现在,我们使用c#编写简单的服务。我们在前面的解决方案中增加一个新的控制台项目,作为Job Worker,代码如下:
using NLog.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
using Zeebe.Client;
using Zeebe.Client.Api.Responses;
using Zeebe.Client.Api.Worker;
namespace ZeebeJobWorker
{
class Program
{
private static readonly string ZeebeUrl = "127.0.0.1:26500";
private static readonly string JobType = "payment-service";
private static readonly string WorkerName = Environment.MachineName;
static async Task Main(string[] args)
{
// create zeebe client
var client = ZeebeClient.Builder()
.UseLoggerFactory(new NLogLoggerFactory())
.UseGatewayAddress(ZeebeUrl)
.UsePlainText()
.Build();
// open job worker
using (var signal = new EventWaitHandle(false, EventResetMode.AutoReset))
{
client.NewWorker()
.JobType(JobType)
.Handler(HandleJob)
.MaxJobsActive(5)
.Name(WorkerName)
.AutoCompletion()
.PollInterval(TimeSpan.FromSeconds(1))
.Timeout(TimeSpan.FromSeconds(10))
.Open();
// blocks main thread, so that worker can run
signal.WaitOne();
}
}
private static void HandleJob(IJobClient jobClient, IJob job)
{
// business logic
var jobKey = job.Key;
Console.WriteLine("Handling job: " + job);
}
}
}
运行这个项目,结果如下:
图片.png
如果在Operator中查看,会发现流程执行到第二个环节:
图片.png
我们可以用同样的方法为其它环节编写服务。