In this tutorial, you will learn to use the Go client in a Go application to interact with Zeebe.
You will be guided through the following steps:
- Set up a project
- Model a workflow
- Deploy a workflow
- Create a workflow instance
- Work on a task
- Open a topic subscription
You can find the complete source code, on GitHub.
Before you begin to setup your project please start the broker, i.e. by running the start up script
bin/broker.bat in the distribution. Per default the broker is binding to the
localhost:26500, which is used as contact point in this guide. In case your broker is
available under another address please adjust the broker contact point when building the client.
First, we need a new Go project. Create a new project using your IDE, or create new Go module with:
To use the Zeebe Go client library, add the following dependency to your
main.go file inside the module and add the following lines to bootstrap the Zeebe client:
Run the program.
You should see similar output:
Now, we need a first workflow which can then be deployed. Later, we will extend the workflow with more functionality.
Open the Zeebe Modeler and create a new BPMN diagram. Add a start event and an end event to the diagram and connect the events.
Set the id to
order-process (i.e., the BPMN process id) and mark the diagram
as executable. Save the diagram in the project's source folder.
Next, we want to deploy the modeled workflow to the broker. The broker stores the workflow under its BPMN process id and assigns a version (i.e., the revision).
Run the program and verify that the workflow is deployed successfully. You should see similar the output:
Finally, we are ready to create a first instance of the deployed workflow. A workflow instance is created of a specific version of the workflow, which can be set on creation.
Run the program and verify that the workflow instance is created. You should see the output:
You did it! You want to see how the workflow instance is executed?
Start the Zeebe Monitor using
java -jar zeebe-simple-monitor-app-*.jar.
Open a web browser and go to http://localhost:8080/.
Here, you see the current state of the workflow instance.
Now we want to do some work within your workflow. First, add a few service
tasks to the BPMN diagram and set the required attributes. Then extend your
main.go file and activate a job which are created when the workflow instance
reaches a service task.
Open the BPMN diagram in the Zeebe Modeler. Insert a few service tasks between the start and the end event.
You need to set the type of each task, which identifies the nature of the work to be performed.
Set the type of the first task to
Add the following lines to redeploy the modified process, then activate and complete a job of the first task type:
In this example we open a job worker for jobs of type
The job worker will repeatedly poll for new jobs of the type
payment-service and activate them
subsequently. Each activated job will then be passed to the job handler which implements the business
logic of the job worker. The handler will then complete the job with its result or fail the job if
it encounters a problem while processing the job.
When you have a look at the Zeebe Monitor, then you can see that the workflow instance moved from the first service task to the next one:
When you run the above example you should see similar output:
Yay! You finished this tutorial and learned the basic usage of the Go client.