Class ZeebeClientImpl
- All Implemented Interfaces:
JobClient,ZeebeClient,AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionZeebeClientImpl(ZeebeClientConfiguration configuration) ZeebeClientImpl(ZeebeClientConfiguration configuration, io.grpc.ManagedChannel channel) ZeebeClientImpl(ZeebeClientConfiguration configuration, io.grpc.ManagedChannel channel, HttpClient httpClient) ZeebeClientImpl(ZeebeClientConfiguration configuration, io.grpc.ManagedChannel channel, GatewayGrpc.GatewayStub gatewayStub) ZeebeClientImpl(ZeebeClientConfiguration config, io.grpc.ManagedChannel channel, GatewayGrpc.GatewayStub gatewayStub, ExecutorResource executorResource) ZeebeClientImpl(ZeebeClientConfiguration config, io.grpc.ManagedChannel channel, GatewayGrpc.GatewayStub gatewayStub, ExecutorResource executorResource, HttpClient httpClient) -
Method Summary
Modifier and TypeMethodDescriptionstatic io.grpc.ManagedChannelbuildChannel(ZeebeClientConfiguration config) static GatewayGrpc.GatewayStubbuildGatewayStub(io.grpc.ManagedChannel channel, ZeebeClientConfiguration config) voidclose()Command to activate multiple jobs of a given type.Command to broadcast a signal.newCancelInstanceCommand(long processInstanceKey) Command to cancel a process instance.newCompleteCommand(long jobKey) Command to complete a job.Command to complete a job.Command to create/start a new instance of a process.newDeleteResourceCommand(long resourceKey) Command to delete a resource.Command to deploy new processes.Command to deploy new resources, i.e.Command to evaluate a decision.newFailCommand(long jobKey) Command to mark a job as failed.Command to mark a job as failed.newMigrateProcessInstanceCommand(long processInstanceKey) Command to migrate a process instance to a different process definition.newModifyProcessInstanceCommand(long processInstanceKey) Command to modify a process instance.Command to publish a message which can be correlated to a process instance.newResolveIncidentCommand(long incidentKey) Command to resolve an existing incident.newSetVariablesCommand(long elementInstanceKey) Command to set and/or update the variables of a given flow element (e.g.Activates and streams jobs of a specific type.newThrowErrorCommand(long jobKey) Command to report a business error (i.e.Command to report a business error (i.e.Request the current cluster topology.newUpdateRetriesCommand(long jobKey) Command to update the retries of a job.Command to update the retries of a job.newUpdateTimeoutCommand(long jobKey) Command to update the timeout of a job.Command to update the timeout of a job.newUserTaskAssignCommand(long userTaskKey) Command to assign a user task.newUserTaskCompleteCommand(long userTaskKey) Command to complete a user task.newUserTaskUnassignCommand(long userTaskKey) Command to unassign a user task.newUserTaskUpdateCommand(long userTaskKey) Command to update a user task.Registers a new job worker for jobs of a given type.
-
Constructor Details
-
ZeebeClientImpl
-
ZeebeClientImpl
-
ZeebeClientImpl
public ZeebeClientImpl(ZeebeClientConfiguration configuration, io.grpc.ManagedChannel channel, HttpClient httpClient) -
ZeebeClientImpl
public ZeebeClientImpl(ZeebeClientConfiguration configuration, io.grpc.ManagedChannel channel, GatewayGrpc.GatewayStub gatewayStub) -
ZeebeClientImpl
public ZeebeClientImpl(ZeebeClientConfiguration config, io.grpc.ManagedChannel channel, GatewayGrpc.GatewayStub gatewayStub, ExecutorResource executorResource) -
ZeebeClientImpl
public ZeebeClientImpl(ZeebeClientConfiguration config, io.grpc.ManagedChannel channel, GatewayGrpc.GatewayStub gatewayStub, ExecutorResource executorResource, HttpClient httpClient)
-
-
Method Details
-
buildChannel
-
buildGatewayStub
public static GatewayGrpc.GatewayStub buildGatewayStub(io.grpc.ManagedChannel channel, ZeebeClientConfiguration config) -
newTopologyRequest
Description copied from interface:ZeebeClientRequest the current cluster topology. Can be used to inspect which brokers are available at which endpoint and which broker is the leader of which partition.List<BrokerInfo> brokers = zeebeClient .newTopologyRequest() .send() .join() .getBrokers(); InetSocketAddress address = broker.getSocketAddress(); List<PartitionInfo> partitions = broker.getPartitions();
- Specified by:
newTopologyRequestin interfaceZeebeClient- Returns:
- the request where you must call
send()
-
getConfiguration
- Specified by:
getConfigurationin interfaceZeebeClient- Returns:
- the client's configuration
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceZeebeClient
-
newDeployCommand
Description copied from interface:ZeebeClientCommand to deploy new processes.zeebeClient .newDeployCommand() .addResourceFile("~/wf/process1.bpmn") .addResourceFile("~/wf/process2.bpmn") .send();- Specified by:
newDeployCommandin interfaceZeebeClient- Returns:
- a builder for the command
-
newDeployResourceCommand
Description copied from interface:ZeebeClientCommand to deploy new resources, i.e. BPMN process models and DMN decision models.zeebeClient .newDeployCommand() .addResourceFile("~/wf/process1.bpmn") .addResourceFile("~/wf/process2.bpmn") .addResourceFile("~/dmn/decision.dmn") .send();- Specified by:
newDeployResourceCommandin interfaceZeebeClient- Returns:
- a builder for the command
-
newCreateInstanceCommand
Description copied from interface:ZeebeClientCommand to create/start a new instance of a process.zeebeClient .newCreateInstanceCommand() .bpmnProcessId("my-process") .latestVersion() .variables(json) .send();- Specified by:
newCreateInstanceCommandin interfaceZeebeClient- Returns:
- a builder for the command
-
newModifyProcessInstanceCommand
Description copied from interface:ZeebeClientCommand to modify a process instance.zeebeClient .newModifyProcessInstanceCommand(processInstanceKey) .activateElement("element1") .and() .activateElement("element2") .withVariables(globalScopedVariables) .withVariables(localScopedVariables, "element2") .and() .terminateElement("element3") .send();- Specified by:
newModifyProcessInstanceCommandin interfaceZeebeClient- Parameters:
processInstanceKey- the key which identifies the corresponding process instance- Returns:
- a builder for the command
-
newMigrateProcessInstanceCommand
Description copied from interface:ZeebeClientCommand to migrate a process instance to a different process definition.The migration command contains a migration plan. Migration plan contains targetProcessDefinitionKey to indicate which process definition to use for the migration. Mapping instructions for the migration describe how to map elements from the source process definition to the target process definition.
For example, let's consider we want to migrate process instance with key
1, target process definition key2, a source process definition with a service task with id"task1"and the target process definition with a service task with id"task2". The migration command could be:{ "processInstanceKey": 1, "migrationPlan": { "targetProcessDefinitionKey": 2, "mappingInstructions": [ { "sourceElementId": "task1", "targetElementId": "task2" } ] } }zeebeClient .newMigrateProcessInstanceCommand(1L) .migrationPlan(2L) .addMappingInstruction("element1", "element2") .addMappingInstruction("element3", "element4") .send();final MigrationPlan migrationPlan = MigrationPlan.newBuilder() .withTargetProcessDefinitionKey(2L) .addMappingInstruction("element1", "element2") .addMappingInstruction("element3", "element4") .build(); zeebeClient .newMigrateProcessInstanceCommand(1L) .migrationPlan(migrationPlan) .send();- Specified by:
newMigrateProcessInstanceCommandin interfaceZeebeClient- Parameters:
processInstanceKey- the key which refers to the process instance to migrate- Returns:
- a builder for the command
-
newCancelInstanceCommand
Description copied from interface:ZeebeClientCommand to cancel a process instance.zeebeClient .newCancelInstanceCommand(processInstanceKey) .send();
- Specified by:
newCancelInstanceCommandin interfaceZeebeClient- Parameters:
processInstanceKey- the key which identifies the corresponding process instance- Returns:
- a builder for the command
-
newSetVariablesCommand
Description copied from interface:ZeebeClientCommand to set and/or update the variables of a given flow element (e.g. process instance, task, etc.)zeebeClient .newSetVariablesCommand(elementInstanceKey) .variables(json) .send();
- Specified by:
newSetVariablesCommandin interfaceZeebeClient- Parameters:
elementInstanceKey- the key of the element instance to set/update the variables for- Returns:
- a builder for the command
-
newEvaluateDecisionCommand
Description copied from interface:ZeebeClientCommand to evaluate a decision.zeebeClient .newEvaluateDecisionCommand() .decisionKey("my-decision") .variables(json) .send();- Specified by:
newEvaluateDecisionCommandin interfaceZeebeClient- Returns:
- a builder for the command
-
newPublishMessageCommand
Description copied from interface:ZeebeClientCommand to publish a message which can be correlated to a process instance.zeebeClient .newPublishMessageCommand() .messageName("order canceled") .correlationKey(orderId) .variables(json) .send();- Specified by:
newPublishMessageCommandin interfaceZeebeClient- Returns:
- a builder for the command
-
newBroadcastSignalCommand
Description copied from interface:ZeebeClientCommand to broadcast a signal.zeebeClient .newBroadcastSignalCommand() .signalName("signal") .variables(json) .send();- Specified by:
newBroadcastSignalCommandin interfaceZeebeClient- Returns:
- a builder for the command
-
newResolveIncidentCommand
Description copied from interface:ZeebeClientCommand to resolve an existing incident.zeebeClient .newResolveIncidentCommand(incidentKey) .send();
- Specified by:
newResolveIncidentCommandin interfaceZeebeClient- Parameters:
incidentKey- the key of the corresponding incident- Returns:
- the builder for the command
-
newUpdateRetriesCommand
Description copied from interface:ZeebeClientCommand to update the retries of a job.long jobKey = ..; zeebeClient .newUpdateRetriesCommand(jobKey) .retries(3) .send();
If the given retries are greater than zero then this job will be picked up again by a job worker. This will not close a related incident, which still has to be marked as resolved with
newResolveIncidentCommand(long incidentKey).- Specified by:
newUpdateRetriesCommandin interfaceZeebeClient- Parameters:
jobKey- the key of the job to update- Returns:
- a builder for the command
-
newUpdateRetriesCommand
Description copied from interface:ZeebeClientCommand to update the retries of a job.ActivatedJob job= ..; zeebeClient .newUpdateRetriesCommand(job) .retries(3) .send();
If the given retries are greater than zero then this job will be picked up again by a job worker. This will not close a related incident, which still has to be marked as resolved with
newResolveIncidentCommand(long incidentKey).- Specified by:
newUpdateRetriesCommandin interfaceZeebeClient- Parameters:
job- the activated job- Returns:
- a builder for the command
-
newUpdateTimeoutCommand
Description copied from interface:ZeebeClientCommand to update the timeout of a job.long jobKey = ..; zeebeClient .newUpdateTimeoutCommand(jobKey) .timeout(100) .send();
Timeout value in millis is used to calculate a new job deadline. This will happen when the command to update the timeline is processed. The timeout value will be added to the current time then.
- Specified by:
newUpdateTimeoutCommandin interfaceZeebeClient- Parameters:
jobKey- the key of the job to update- Returns:
- a builder for the command
-
newUpdateTimeoutCommand
Description copied from interface:ZeebeClientCommand to update the timeout of a job.ActivatedJob job= ..; zeebeClient .newUpdateTimeoutCommand(job) .timeout(100) .send();
Timeout value in millis is used to calculate a new job deadline. This will happen when the command to update the timeline is processed. The timeout value will be added to the current time then.
- Specified by:
newUpdateTimeoutCommandin interfaceZeebeClient- Parameters:
job- the activated job- Returns:
- a builder for the command
-
newWorker
Description copied from interface:ZeebeClientRegisters a new job worker for jobs of a given type.After registration, the broker activates available jobs and assigns them to this worker. It then publishes them to the client. The given worker is called for every received job, works on them and eventually completes them.
JobWorker worker = zeebeClient .newWorker() .jobType("payment") .handler(paymentHandler) .open(); ... worker.close();Example JobHandler implementation:public final class PaymentHandler implements JobHandler { @Override public void handle(JobClient client, JobEvent jobEvent) { String json = jobEvent.getVariables(); // modify variables client .newCompleteCommand() .event(jobEvent) .variables(json) .send(); } };- Specified by:
newWorkerin interfaceZeebeClient- Returns:
- a builder for the worker registration
-
newDeleteResourceCommand
Description copied from interface:ZeebeClientCommand to delete a resource.zeebeClient .newDeleteResourceCommand(resourceKey) .send();
- Specified by:
newDeleteResourceCommandin interfaceZeebeClient- Parameters:
resourceKey- the key of the resource- Returns:
- the builder for the command
-
newUserTaskCompleteCommand
Description copied from interface:ZeebeClientCommand to complete a user task.long userTaskKey = ..; zeebeClient .newUserTaskCompleteCommand(userTaskKey) .variables(map) .send();
If the user task is linked to a process instance then this command will complete the related activity and continue the flow.
This command is only sent via REST over HTTP, not via gRPC
Experimental: This method is under development, and as such using it may have no effect on the client builder when called. Until this warning is removed, anything described below may not yet have taken effect, and the interface and its description are subject to change.
- Specified by:
newUserTaskCompleteCommandin interfaceZeebeClient- Parameters:
userTaskKey- the key of the user task- Returns:
- a builder for the command
-
newUserTaskAssignCommand
Description copied from interface:ZeebeClientCommand to assign a user task.long userTaskKey = ..; zeebeClient .newUserTaskAssignCommand(userTaskKey) .assignee(newAssignee) .send();
This command is only sent via REST over HTTP, not via gRPC
Experimental: This method is under development, and as such using it may have no effect on the client builder when called. Until this warning is removed, anything described below may not yet have taken effect, and the interface and its description are subject to change.
- Specified by:
newUserTaskAssignCommandin interfaceZeebeClient- Parameters:
userTaskKey- the key of the user task- Returns:
- a builder for the command
-
newUserTaskUpdateCommand
Description copied from interface:ZeebeClientCommand to update a user task.long userTaskKey = ..; zeebeClient .newUserTaskUpdateCommand(userTaskKey) .candidateGroups(newCandidateGroups) .send();
This command is only sent via REST over HTTP, not via gRPC
Experimental: This method is under development, and as such using it may have no effect on the client builder when called. Until this warning is removed, anything described below may not yet have taken effect, and the interface and its description are subject to change.
- Specified by:
newUserTaskUpdateCommandin interfaceZeebeClient- Parameters:
userTaskKey- the key of the user task- Returns:
- a builder for the command
-
newUserTaskUnassignCommand
Description copied from interface:ZeebeClientCommand to unassign a user task.long userTaskKey = ..; zeebeClient .newUserTaskUnassignCommand(userTaskKey) .send();
This command is only sent via REST over HTTP, not via gRPC
Experimental: This method is under development, and as such using it may have no effect on the client builder when called. Until this warning is removed, anything described below may not yet have taken effect, and the interface and its description are subject to change.
- Specified by:
newUserTaskUnassignCommandin interfaceZeebeClient- Parameters:
userTaskKey- the key of the user task- Returns:
- a builder for the command
-
newCompleteCommand
Description copied from interface:JobClientCommand to complete a job.long jobKey = ..; jobClient .newCompleteCommand(jobKey) .variables(json) .send();
If the job is linked to a process instance then this command will complete the related activity and continue the flow.
- Specified by:
newCompleteCommandin interfaceJobClient- Parameters:
jobKey- the key which identifies the job- Returns:
- a builder for the command
-
newCompleteCommand
Description copied from interface:JobClientCommand to complete a job.ActivatedJob job = ..; jobClient .newCompleteCommand(job) .variables(json) .send();
If the job is linked to a process instance then this command will complete the related activity and continue the flow.
- Specified by:
newCompleteCommandin interfaceJobClient- Parameters:
job- the activated job- Returns:
- a builder for the command
-
newFailCommand
Description copied from interface:JobClientCommand to mark a job as failed.long jobKey = ..; jobClient .newFailCommand(jobKey) .retries(3) .send();
If the given retries are greater than zero then this job will be picked up again by a job subscription. Otherwise, an incident is created for this job.
- Specified by:
newFailCommandin interfaceJobClient- Parameters:
jobKey- the key which identifies the job- Returns:
- a builder for the command
-
newFailCommand
Description copied from interface:JobClientCommand to mark a job as failed.ActivatedJob job = ..; jobClient .newFailCommand(job) .retries(3) .send();
If the given retries are greater than zero then this job will be picked up again by a job subscription. Otherwise, an incident is created for this job.
- Specified by:
newFailCommandin interfaceJobClient- Parameters:
job- the activated job- Returns:
- a builder for the command
-
newThrowErrorCommand
Description copied from interface:JobClientCommand to report a business error (i.e. non-technical) that occurs while processing a job.long jobKey = ...; String code = ...; jobClient .newThrowErrorCommand(jobKey) .errorCode(code) .send();
The error is handled in the process by an error catch event. If there is no error catch event with the specified errorCode then an incident will be raised instead.
- Specified by:
newThrowErrorCommandin interfaceJobClient- Parameters:
jobKey- the key which identifies the job- Returns:
- a builder for the command
-
newThrowErrorCommand
Description copied from interface:JobClientCommand to report a business error (i.e. non-technical) that occurs while processing a job.ActivatedJob job = ...; String code = ...; jobClient .newThrowErrorCommand(job) .errorCode(code) .send();
The error is handled in the process by an error catch event. If there is no error catch event with the specified errorCode then an incident will be raised instead.
- Specified by:
newThrowErrorCommandin interfaceJobClient- Parameters:
job- the activated job- Returns:
- a builder for the command
-
newActivateJobsCommand
Description copied from interface:JobClientCommand to activate multiple jobs of a given type.jobClient .newActivateJobsCommand() .jobType("payment") .maxJobsToActivate(10) .workerName("paymentWorker") .timeout(Duration.ofMinutes(10)) .send();The command will try to use
maxJobsToActivatefor givenjobType. If less then the requestedmaxJobsToActivatejobs of thejobTypeare available for activation the returned list will have fewer elements.- Specified by:
newActivateJobsCommandin interfaceJobClient- Returns:
- a builder for the command
-
newStreamJobsCommand
Description copied from interface:JobClientActivates and streams jobs of a specific type.final Consumer<ActivatedJob> consumer = ...; // do something with the consumed job final ZeebeFuture<StreamJobsResponse> stream = jobClient .newStreamJobsCommand() .jobType("payment") .consumer(consumer) .workerName("paymentWorker") .timeout(Duration.ofMinutes(10)) .send(); stream.whenComplete((ok, error) -> { // recreate stream if necessary // be careful if you've cancelled the stream explicitly to not recreate it if shutting down }); // You can later terminate the stream by cancelling the future stream.cancel(true);Stream or Activate?
As opposed to
JobClient.newActivateJobsCommand(), which polls each partition until it has activated enough jobs or a timeout has elapsed, this command opens a long living stream onto which activated jobs are pushed. This typically results in lower latency, as jobs are activated and pushed out immediately, instead of waiting to be polled.Limitations
This feature is still under development; as such, there is currently no way to rate limit how many jobs are streamed over a single call. This can be mitigated by opening more streams of the same type, which will ensure work is fairly load balanced.
Additionally, only jobs which are created, retried, or timed out after the command has been registered will be streamed out. For older jobs, you must still use the
JobClient.newActivateJobsCommand(). It's generally recommended that you use theJobWorkerAPI to avoid having to coordinate both calls.Activation
Jobs activated via this command will use the given worker name, activation time out, and fetch variables parameters in the same way as the
JobClient.newActivateJobsCommand().Termination
The stream can be explicitly cancelled by performing one of the following:
- Closing the Zeebe client
- Cancelling the result of
FinalCommandStep.send()viaFuture.cancel(boolean)(the argument is irrelevant) - Setting a
FinalCommandStep.requestTimeout(Duration); the stream will be closed once this time out is reached. By default, there is no request time out at all. It's recommended to assign a long-ish time out and recreate your streams from time to time to ensure good load balancing across gateways.
- Specified by:
newStreamJobsCommandin interfaceJobClient- Returns:
- a builder for the command
-