Create a Workflow Instance and Await Result


  1. Running Zeebe broker with endpoint localhost:26500 (default)
  2. Run the Deploy a Workflow example. Deploy demoProcessSingleTask.bpmn instead of demoProcess.bpmn

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.workflow;

import io.zeebe.client.ZeebeClient;
import io.zeebe.client.ZeebeClientBuilder;
import io.zeebe.client.api.response.WorkflowInstanceResult;
import java.time.Duration;
import java.util.Map;

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

    final String bpmnProcessId = "demoProcessSingleTask";

    final ZeebeClientBuilder builder =

    try (final ZeebeClient client = {

      openJobWorker(client); // open job workers so that task are executed and workflow is completed
      System.out.println("Creating workflow instance");

      final WorkflowInstanceResult workflowInstanceResult =
              .withResult() // to await the completion of workflow execution and return result

          "Workflow instance created with key: "
              + workflowInstanceResult.getWorkflowInstanceKey()
              + " and completed with results: "
              + workflowInstanceResult.getVariables());

  private static void openJobWorker(final ZeebeClient client) {
            (jobClient, job) ->
                    .variables(Map.of("job", job.getKey()))