public interface JobClient
Modifier and Type | Method and Description |
---|---|
ActivateJobsCommandStep1 |
newActivateJobsCommand()
Command to activate multiple jobs of a given type.
|
CompleteJobCommandStep1 |
newCompleteCommand(long jobKey)
Command to complete a job.
|
CreateJobCommandStep1 |
newCreateCommand()
Command to create a new (standalone) job.
|
FailJobCommandStep1 |
newFailCommand(long jobKey)
Command to mark a job as failed.
|
UpdateRetriesJobCommandStep1 |
newUpdateRetriesCommand(long jobKey)
Command to update the retries of a job.
|
JobWorkerBuilderStep1 |
newWorker()
Registers a new job worker for jobs of a given type.
|
CreateJobCommandStep1 newCreateCommand()
jobClient .newCreateCommand() .type("my-todos") .payload(json) .send();
CompleteJobCommandStep1 newCompleteCommand(long jobKey)
long jobKey = ..; jobClient .newCompleteCommand(jobKey) .payload(json) .send();The job is specified by the given event. The event must be the latest event of the job to ensure that the command is based on the latest state of the job. If it's not the latest one then the command is rejected.
If the job is linked to a workflow instance then this command will complete the related activity and continue the flow.
event
- the latest job eventFailJobCommandStep1 newFailCommand(long jobKey)
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.
jobKey
- the key of the jobUpdateRetriesJobCommandStep1 newUpdateRetriesCommand(long jobKey)
long jobKey = ..; jobClient .newUpdateRetriesCommand(jobKey) .retries(3) .send();
If the given retries are greater than zero then this job will be picked up again by a job subscription and a related incident will be marked as resolved.
jobKey
- the key of the job to updateJobWorkerBuilderStep1 newWorker()
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 = jobClient .newWorker() .jobType("payment") .handler(paymentHandler) .open(); ... worker.close();Example JobHandler implementation:
public class PaymentHandler implements JobHandler { @Override public void handle(JobClient client, JobEvent jobEvent) { String json = jobEvent.getPayload(); // modify payload client .newCompleteCommand() .event(jobEvent) .payload(json) .send(); } };
ActivateJobsCommandStep1 newActivateJobsCommand()
jobClient .newActivateJobsCommand() .jobType("payment") .amount(10) .workerName("paymentWorker") .timeout(Duration.ofMinutes(10)) .send();
The command will try to activate maximal amount
jobs of given jobType
. If
less then amount
jobs of the jobType
are available for activation the returned
list will have fewer elements.
Copyright © 2017–2018 camunda services GmbH. All rights reserved.