Java client
Dependencies
To use the Java client library, declare the following Maven dependency in your project:
<dependency>
<groupId>io.camunda</groupId>
<artifactId>zeebe-client-java</artifactId>
<version>${zeebe.version}</version>
</dependency>
If you are using Gradle, declare the following:
implementation 'io.camunda:zeebe-client-java:${zeebe.version}'
Use the latest released version from Maven Central.
Bootstrapping
In Java code, instantiate the client as follows:
private static final String zeebeAPI = "[Zeebe Address e.g. f887f1a6-7c2b-48ce-809a-e11e5a6ba31a.dsm-1.zeebe.camunda.io:443]";
private static final String audience = "[Zeebe Token Audience, e.g., zeebe.camunda.io]";
private static final String clientId = "[Client ID, e.g., FmT7K8gVv_FcwiUhc8U-fAJ9wph0Kn~P]";
private static final String clientSecret = "[Client Secret]";
private static final String oAuthAPI = "[OAuth API, e.g., https://login.cloud.camunda.io/oauth/token] ";
public static void main(String[] args) {
OAuthCredentialsProvider credentialsProvider =
new OAuthCredentialsProviderBuilder()
.authorizationServerUrl(oAuthAPI)
.audience(audience)
.clientId(clientId)
.clientSecret(clientSecret)
.build();
try (ZeebeClient client = ZeebeClient.newClientBuilder()
.gatewayAddress(zeebeAddress)
.credentialsProvider(credentialsProvider)
.build()) {
client.newTopologyRequest().send().join();
}
}
Let's go over this code snippet line by line:
- Declare a few variables to define the connection properties. These values can be taken from the connection information on the Client Credentials page. Note that
clientSecret
is only visible when you create the client credentials. - Create the credentials provider for the OAuth protocol. This is needed to authenticate your client.
- Create the client by passing in the address of the cluster we want to connect to and the credentials provider from the step above. Note that a client should be closed after usage, which is easily achieved by the try-with-resources statement.
- Send a test request to verify the connection was established.
See io.camunda.zeebe.client.ZeebeClientBuilder for a description of all available configuration properties.
Another (more compact) option is to pass in the connection settings via environment variables:
export ZEEBE_ADDRESS='[Zeebe Address]'
export ZEEBE_CLIENT_ID='[Client ID]'
export ZEEBE_CLIENT_SECRET='[Client Secret]'
export ZEEBE_AUTHORIZATION_SERVER_URL='[OAuth API]'
When you create client credentials in Camunda 8, you have the option to download a file with the lines above filled out for you.
Given these environment variables, you can instantiate the client as follows:
ZeebeClient client =
ZeebeClient.newClientBuilder()
.gatewayAddress(System.getenv("ZEEBE_ADDRESS"))
.build();
Javadoc
The official Java client library API documentation can be found here. These are standard Javadocs, so your favorite JVM IDE will be able to install them locally as well.
Next steps
- Getting Started Guide: A comprehensive tutorial that covers Camunda Modeler, Operate, and the Java client.
- Job worker: An introduction to the Java client's job worker.
- Logging: An introduction to configuring logging for a Zeebe client.
- Writing tests: An introduction to unit testing processes.
- Examples: A collection of specific examples for different use cases.