public class JobWorkerBuilderImpl extends Object implements JobWorkerBuilderStep1, JobWorkerBuilderStep1.JobWorkerBuilderStep2, JobWorkerBuilderStep1.JobWorkerBuilderStep3
JobWorkerBuilderStep1.JobWorkerBuilderStep2, JobWorkerBuilderStep1.JobWorkerBuilderStep3
Constructor and Description |
---|
JobWorkerBuilderImpl(ZeebeClientConfiguration configuration,
GatewayGrpc.GatewayStub gatewayStub,
JobClient jobClient,
ZeebeObjectMapper objectMapper,
ScheduledExecutorService executorService,
List<CloseableSilently> closeables) |
Modifier and Type | Method and Description |
---|---|
JobWorkerBuilderStep1.JobWorkerBuilderStep3 |
bufferSize(int numberOfJobs)
Set the maximum number of jobs which will be exclusively assigned to this worker at the same
time.
|
JobWorkerBuilderStep1.JobWorkerBuilderStep3 |
handler(JobHandler handler)
Set the handler to process the jobs.
|
JobWorkerBuilderStep1.JobWorkerBuilderStep2 |
jobType(String type)
Set the type of jobs to work on.
|
JobWorkerBuilderStep1.JobWorkerBuilderStep3 |
name(String workerName)
Set the name of the worker owner.
|
JobWorker |
open()
Open the worker and start to work on available tasks.
|
JobWorkerBuilderStep1.JobWorkerBuilderStep3 |
pollInterval(java.time.Duration pollInterval)
Set the maximal interval between polling for new jobs.
|
JobWorkerBuilderStep1.JobWorkerBuilderStep3 |
timeout(java.time.Duration timeout)
Set the time for how long a job is exclusively assigned for this worker.
|
JobWorkerBuilderStep1.JobWorkerBuilderStep3 |
timeout(long timeout)
Set the time for how long a job is exclusively assigned for this worker.
|
public JobWorkerBuilderImpl(ZeebeClientConfiguration configuration, GatewayGrpc.GatewayStub gatewayStub, JobClient jobClient, ZeebeObjectMapper objectMapper, ScheduledExecutorService executorService, List<CloseableSilently> closeables)
public JobWorkerBuilderStep1.JobWorkerBuilderStep2 jobType(String type)
JobWorkerBuilderStep1
jobType
in interface JobWorkerBuilderStep1
type
- the type of jobs (e.g. "payment")public JobWorkerBuilderStep1.JobWorkerBuilderStep3 handler(JobHandler handler)
JobWorkerBuilderStep1.JobWorkerBuilderStep2
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(); } };The handler must be thread-safe.
handler
in interface JobWorkerBuilderStep1.JobWorkerBuilderStep2
handler
- the handle to process the jobspublic JobWorkerBuilderStep1.JobWorkerBuilderStep3 timeout(long timeout)
JobWorkerBuilderStep1.JobWorkerBuilderStep3
In this time, the job can not be assigned by other workers to ensure that only one worker work on the job. When the time is over then the job can be assigned again by this or other worker if it's not completed yet.
If no timeout is set, then the default is used from the configuration.
timeout
in interface JobWorkerBuilderStep1.JobWorkerBuilderStep3
timeout
- the time in millisecondspublic JobWorkerBuilderStep1.JobWorkerBuilderStep3 timeout(java.time.Duration timeout)
JobWorkerBuilderStep1.JobWorkerBuilderStep3
In this time, the job can not be assigned by other workers to ensure that only one worker work on the job. When the time is over then the job can be assigned again by this or other worker if it's not completed yet.
If no time is set then the default is used from the configuration.
timeout
in interface JobWorkerBuilderStep1.JobWorkerBuilderStep3
timeout
- the time as duration (e.g. "Duration.ofMinutes(5)")public JobWorkerBuilderStep1.JobWorkerBuilderStep3 name(String workerName)
JobWorkerBuilderStep1.JobWorkerBuilderStep3
This name is used to identify the worker to which a job is exclusively assigned to.
If no name is set then the default is used from the configuration.
name
in interface JobWorkerBuilderStep1.JobWorkerBuilderStep3
workerName
- the name of the worker (e.g. "payment-service")public JobWorkerBuilderStep1.JobWorkerBuilderStep3 bufferSize(int numberOfJobs)
JobWorkerBuilderStep1.JobWorkerBuilderStep3
This is used to control the backpressure of the worker. When the number of assigned jobs is reached then the broker will stop assigning new jobs to the worker in order to to not overwhelm the client and give other workers the chance to work on the jobs. The broker will assign new jobs again when jobs are completed (or marked as failed) which were assigned to the worker.
If no buffer size is set then the default is used from the ZeebeClientConfiguration
.
Considerations:
time spent in buffer + time job handler needs until job completion < job timeout
.bufferSize
in interface JobWorkerBuilderStep1.JobWorkerBuilderStep3
numberOfJobs
- the number of assigned jobspublic JobWorkerBuilderStep1.JobWorkerBuilderStep3 pollInterval(java.time.Duration pollInterval)
JobWorkerBuilderStep1.JobWorkerBuilderStep3
A job worker will automatically try to always activate new jobs after completing jobs. If no jobs can be activated after completing the worker will periodically poll for new jobs.
If no poll interval is set then the default is used from the ZeebeClientConfiguration
pollInterval
in interface JobWorkerBuilderStep1.JobWorkerBuilderStep3
pollInterval
- the maximal interval to check for new jobspublic JobWorker open()
JobWorkerBuilderStep1.JobWorkerBuilderStep3
open
in interface JobWorkerBuilderStep1.JobWorkerBuilderStep3
Copyright © 2017–2018 camunda services GmbH. All rights reserved.