gpt4 book ai didi

io.zeebe.client.ZeebeClient.newWorker()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 01:09:31 27 4
gpt4 key购买 nike

本文整理了Java中io.zeebe.client.ZeebeClient.newWorker()方法的一些代码示例,展示了ZeebeClient.newWorker()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZeebeClient.newWorker()方法的具体详情如下:
包路径:io.zeebe.client.ZeebeClient
类名称:ZeebeClient
方法名:newWorker

ZeebeClient.newWorker介绍

[英]Registers a new job worker for jobs of a given type.

After registration, the broker activates available jobs and assigns them to this worker. It then publishes them to the client. The given worker is called for every received job, works on them and eventually completes them.

JobWorker worker = zeebeClient 
.newWorker() 
.jobType("payment") 
.handler(paymentHandler) 
.open(); 
... 
worker.close();

Example JobHandler implementation:

public class PaymentHandler implements JobHandler 
{ 
@Override 
public void handle(JobClient client, JobEvent jobEvent) 
{ 
String json = jobEvent.getPayload(); 
// modify payload 
client 
.newCompleteCommand() 
.event(jobEvent) 
.payload(json) 
.send(); 
} 
};

[中]为给定类型的作业注册新工作人员。
注册后,代理激活可用的作业并将其分配给该工作者。然后将它们发布到客户端。给定的工人被要求完成每一项接收到的工作,完成这些工作,并最终完成它们。

JobWorker worker = zeebeClient 
.newWorker() 
.jobType("payment") 
.handler(paymentHandler) 
.open(); 
... 
worker.close();

作业处理程序实现示例:

public class PaymentHandler implements JobHandler 
{ 
@Override 
public void handle(JobClient client, JobEvent jobEvent) 
{ 
String json = jobEvent.getPayload(); 
// modify payload 
client 
.newCompleteCommand() 
.event(jobEvent) 
.payload(json) 
.send(); 
} 
};

代码示例

代码示例来源:origin: zeebe-io/zeebe

/**
 * Creates a new job worker that will handle jobs of type {@param type}.
 *
 * <p>Make sure to close the returned job worker.
 *
 * @param type type of the jobs to handle
 * @param handler handler
 * @return a new JobWorker
 */
public JobWorker createJobWorker(String type, JobHandler handler) {
 return clientRule.getClient().newWorker().jobType(type).handler(handler).open();
}

代码示例来源:origin: io.zeebe/zeebe-test

/**
 * Creates a new job worker that will handle jobs of type {@param type}.
 *
 * <p>Make sure to close the returned job worker.
 *
 * @param type type of the jobs to handle
 * @param handler handler
 * @return a new JobWorker
 */
public JobWorker createJobWorker(String type, JobHandler handler) {
 return clientRule.getClient().newWorker().jobType(type).handler(handler).open();
}

代码示例来源:origin: zeebe-io/zeebe

public static void main(final String[] args) {
 final String broker = "127.0.0.1:26500";
 final String jobType = "foo";
 final ZeebeClientBuilder builder = ZeebeClient.newClientBuilder().brokerContactPoint(broker);
 try (ZeebeClient client = builder.build()) {
  System.out.println("Opening job worker.");
  final JobWorker workerRegistration =
    client
      .newWorker()
      .jobType(jobType)
      .handler(new ExampleJobHandler())
      .timeout(Duration.ofSeconds(10))
      .open();
  System.out.println("Job worker opened and receiving jobs.");
  // call workerRegistration.close() to close it
  // run until System.in receives exit command
  waitUntilSystemInput("exit");
 }
}

代码示例来源:origin: zeebe-io/zeebe

public static void main(final String[] args) {
 final String broker = "127.0.0.1:26500";
 final ZeebeClientBuilder builder = ZeebeClient.newClientBuilder().brokerContactPoint(broker);
 try (ZeebeClient client = builder.build()) {
  final Order order = new Order();
  order.setOrderId(31243);
  client
    .newCreateInstanceCommand()
    .bpmnProcessId("demoProcess")
    .latestVersion()
    .payload(order)
    .send()
    .join();
  client.newWorker().jobType("foo").handler(new DemoJobHandler()).open();
  // run until System.in receives exit command
  waitUntilSystemInput("exit");
 }
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com