Open a Job Worker

Related Resources


  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

Source on github

 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Zeebe Community License 1.0. You may not use this file
 * except in compliance with the Zeebe Community License 1.0.
package io.zeebe.example.job;

import io.zeebe.client.ZeebeClient;
import io.zeebe.client.ZeebeClientBuilder;
import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.worker.JobClient;
import io.zeebe.client.api.worker.JobHandler;
import io.zeebe.client.api.worker.JobWorker;
import java.time.Duration;
import java.util.Scanner;

public final class JobWorkerCreator {
  public static void main(final String[] args) {
    final String broker = "";

    final String jobType = "foo";

    final ZeebeClientBuilder builder =

    try (final ZeebeClient client = {

      System.out.println("Opening job worker.");

      try (final JobWorker workerRegistration =
              .handler(new ExampleJobHandler())
              .open()) {
        System.out.println("Job worker opened and receiving jobs.");

        // run until receives exit command

  private static void waitUntilSystemInput(final String exitCode) {
    try (final Scanner scanner = new Scanner( {
      while (scanner.hasNextLine()) {
        final String nextLine = scanner.nextLine();
        if (nextLine.contains(exitCode)) {

  private static class ExampleJobHandler implements JobHandler {
    public void handle(final JobClient client, final ActivatedJob job) {
      // here: business logic that is executed with every job