Class JobClientImpl
- All Implemented Interfaces:
JobClient
-
Constructor Summary
ConstructorsConstructorDescriptionJobClientImpl
(GatewayGrpc.GatewayStub asyncStub, ZeebeClientConfiguration config, JsonMapper jsonMapper, Predicate<CredentialsProvider.StatusCode> retryPredicate) -
Method Summary
Modifier and TypeMethodDescriptionCommand to activate multiple jobs of a given type.newCompleteCommand
(long jobKey) Command to complete a job.Command to complete a job.newFailCommand
(long jobKey) Command to mark a job as failed.Command to mark a job as failed.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.
-
Constructor Details
-
JobClientImpl
public JobClientImpl(GatewayGrpc.GatewayStub asyncStub, ZeebeClientConfiguration config, JsonMapper jsonMapper, Predicate<CredentialsProvider.StatusCode> retryPredicate)
-
-
Method Details
-
newCompleteCommand
Description copied from interface:JobClient
Command 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:
newCompleteCommand
in interfaceJobClient
- Parameters:
jobKey
- the key which identifies the job- Returns:
- a builder for the command
-
newCompleteCommand
Description copied from interface:JobClient
Command 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:
newCompleteCommand
in interfaceJobClient
- Parameters:
job
- the activated job- Returns:
- a builder for the command
-
newFailCommand
Description copied from interface:JobClient
Command 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:
newFailCommand
in interfaceJobClient
- Parameters:
jobKey
- the key which identifies the job- Returns:
- a builder for the command
-
newFailCommand
Description copied from interface:JobClient
Command 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:
newFailCommand
in interfaceJobClient
- Parameters:
job
- the activated job- Returns:
- a builder for the command
-
newThrowErrorCommand
Description copied from interface:JobClient
Command 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:
newThrowErrorCommand
in interfaceJobClient
- Parameters:
jobKey
- the key which identifies the job- Returns:
- a builder for the command
-
newThrowErrorCommand
Description copied from interface:JobClient
Command 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:
newThrowErrorCommand
in interfaceJobClient
- Parameters:
job
- the activated job- Returns:
- a builder for the command
-
newActivateJobsCommand
Description copied from interface:JobClient
Command 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
maxJobsToActivate
for givenjobType
. If less then the requestedmaxJobsToActivate
jobs of thejobType
are available for activation the returned list will have fewer elements.- Specified by:
newActivateJobsCommand
in interfaceJobClient
- Returns:
- a builder for the command
-
newStreamJobsCommand
Description copied from interface:JobClient
Activates 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 theJobWorker
API 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:
newStreamJobsCommand
in interfaceJobClient
- Returns:
- a builder for the command
-