How to create workflow instance in spring for zeebe

How can i create an instance of workflow in springboot project for the workflow being deployed in zeebe cluster.

@Tauqeer you can use spring Zeebe for that… like for example here:

This is my code

package com.spring.task;

import java.time.Instant;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.spring.task.utilities.Utilities;

import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.response.WorkflowInstanceEvent;
import io.zeebe.client.api.worker.JobClient;
import io.zeebe.spring.client.EnableZeebeClient;
import io.zeebe.spring.client.ZeebeClientLifecycle;
import io.zeebe.spring.client.annotation.ZeebeDeployment;
import io.zeebe.spring.client.annotation.ZeebeWorker;
import lombok.extern.slf4j.Slf4j;

@ZeebeDeployment(classPathResource = “ZeebeCheckBalance2.bpmn”)
public class SpringZeebeApplication {

final static Logger logger = LoggerFactory.getLogger(SpringZeebeApplication.class);

private static ZeebeClientLifecycle client;

Utilities utilities;

Random random = new Random();

final Map<String, Object> result = new HashMap<>();

public static void main(String[] args) {, args);

private static void logJob(final ActivatedJob job) {
			"complete job\n>>> [type: {}, key: {}, element: {}, workflow instance: {}]\n{deadline; {}]\n[headers: {}]\n[variables: {}]",
			job.getType(), job.getKey(), job.getElementId(), job.getWorkflowInstanceKey(),
			Instant.ofEpochMilli(job.getDeadline()), job.getCustomHeaders(), job.getVariables());

@ZeebeWorker(type = "foo")
public void foo(final JobClient client, final ActivatedJob job) {
	client.newCompleteCommand(job.getKey()).variables("{\"fooResult\": 1}").send().join();

@ZeebeWorker(type = "bar")
public void bar(final JobClient client, final ActivatedJob job) {

@Scheduled(fixedRate = 5000L)
public static void startProcesses() {
	if (!client.isRunning()) {

	final WorkflowInstanceEvent event = client.newCreateInstanceCommand().bpmnProcessId("orderManagement")
			.latestVersion().variables("{\"a\": \"" + UUID.randomUUID().toString() + "\"}").send().join();
			"started instance for workflowKey='{}', bpmnProcessId='{}', version='{}' with workflowInstanceKey='{}'",
			event.getWorkflowKey(), event.getBpmnProcessId(), event.getVersion(), event.getWorkflowInstanceKey());

@ZeebeWorker(type = "taskA")
public void taskA(final JobClient client, final ActivatedJob job) {
	//final Map<String, Object> variables =job.getVariablesAsMap();
	logJob(job);"task A has been completed ");
	final Map<String, Object> result = new HashMap<>();
	result.put("condition", random.nextBoolean());

and when i run this im getting null pointer exception
2020-05-22 12:53:15.227 ERROR 21172 — [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task

java.lang.NullPointerException: null
at com.spring.task.SpringZeebeApplication.startProcesses(
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
at java.base/java.lang.reflect.Method.invoke(
at java.base/java.util.concurrent.Executors$
at java.base/java.util.concurrent.FutureTask.runAndReset(
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.base/java.util.concurrent.ThreadPoolExecutor$
at java.base/

What is it in line 172? -> -> java.lang.NullPointerException: null
Debug the source code and see what is null. It sounds like something is not correctly initialized

private static ZeebeClientLifecycle client;

this is causing the problem, its not getting initialized.

@Tauqeer can you share your project in github? to reproduce that issue?
Where your Zeebe Cluster running? are you correctly configuring the client?

Hi @salaboy,
Thank you for your help and i have solved the issue.

private static ZeebeClientLifecycle client;

removed static key word and it worked fine.
But i have one more query, For message based events how to send message to zeebe engine.

@Tauqeer the answer to that is definitely in the docs. But you can see an example here:


@salaboy Thank you so much for the help and guidance.

1 Like

@Tauqeer can you mark this question as solved?

The POM for io.Zeebe:zeebe-client-java:jar:0.18.0-SNAPSHOT is missing, no dependency statistics available" – I Actually did the same, but getting this error. I used vs code in ubuntu as ide

Any reason why you are using 0.18.0? The latest version is 0.23.0.

If you need to use 0.18.0 and it is not available, please check the issues here (including closed issues to see if there is a workaround in there), and open one if there isn’t one for it already.

1 Like

Hi @salaboy,
Hope you are doing well, @salaboy how can i get the details of all the activities and task details in a workflow and even the timers details when i’m creating an instance of workflow.

@Tauqeer you can’t from the APIs exposed by Zeebe, you need to use an exporter to get that information.
Operate uses the ElasticSearch Exporter to get the data out and then show the state of the workflow instances. You can check ZeeQS and Simple Monitor to get that information from those data sources.

@salaboy, Thank you so much for your help, I have one question related to publish message command .
PublishMessageResponse publishMessageResponse = client.newPublishMessageCommand().messageName(messageName)

what does publishMessageResponse hold ? and how will i get to know that it was correlated.
I need to know wheter it was correlated or not because i need to send the status[failure or success]

@Tauqeer you don’t get that information from publishing a message. There is no failure from publishing a message, as I can or cannot be correlated based on the correlation key.
What you can do is to add in your process a notification mechanism to report back. For example, the first Service Task in your process can push data to a component that is in charge of keeping track which workflows were started.

Hope this helps.