Version: latest

Open a job worker

Related Resources#

Prerequisites#

  1. Running Zeebe broker with endpoint localhost:26500 (default)
  2. Run the deploy a workflow example
  3. Run the create a workflow instance example a couple of times

JobWorkerCreator.java#

Source on github

...
final String jobType = "foo";
try (final ZeebeClient client = clientBuilder.build()) {
System.out.println("Opening job worker.");
try (final JobWorker workerRegistration =
client
.newWorker()
.jobType(jobType)
.handler(new ExampleJobHandler())
.timeout(Duration.ofSeconds(10))
.open()) {
System.out.println("Job worker opened and receiving jobs.");
// run until System.in receives exit command
waitUntilSystemInput("exit");
}
}
}
private static class ExampleJobHandler implements JobHandler {
@Override
public void handle(final JobClient client, final ActivatedJob job) {
// here: business logic that is executed with every job
System.out.println(job);
client.newCompleteCommand(job.getKey()).send().join();
}
}