In this tutorial, you will learn how to use the Go client in a Go application to interact with Camunda Cloud.
You can find the complete source code on GitHub.
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
Set the connection settings and client credentials as environment variables:
Hint: When you create client credentials in Camunda Cloud you have the option to download a file with the lines above filled out for you.
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 simple workflow we can deploy. Later, we will extend the workflow with more functionality.
Open the modeler of your choice and create a new BPMN diagram.
Add a start event named
Order Placed and an end event named
Order Delivered to the diagram and connect the events.
Set the id (the BPMN process id), and mark the diagram as executable.
Save the diagram as
src/main/resources/order-process.bpmn under the project's 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.
Run the program and verify that the workflow is deployed successfully. You should see similar the output:
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?
- Go to the cluster in Camunda Cloud and select it
- Click on the link to Operate
- Select the workflow order process
As you can see, a workflow instance has been started and finished.
Now we want to do some work within our 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 modeler. Insert three service tasks between the start and the end event.
- Name the first task
- Name the second task
- Name the third task
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
- Set the type of the second task to
- Set the type of the third task to
The consolidated example looks as follows:
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.