Open a job worker
Related resources​
Prerequisites​
- Run the Zeebe broker with endpoint
localhost:26500
(default). - Run the deploy a process example.
- Run the create a process instance example a few times.
JobWorkerCreator.java​
...
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();
}
}