Interface JobWorkerBuilderStep1.JobWorkerBuilderStep3
- All Superinterfaces:
CommandWithOneOrMoreTenantsStep<JobWorkerBuilderStep1.JobWorkerBuilderStep3>,CommandWithTenantStep<JobWorkerBuilderStep1.JobWorkerBuilderStep3>
- All Known Implementing Classes:
JobWorkerBuilderImpl
- Enclosing interface:
JobWorkerBuilderStep1
-
Field Summary
Fields inherited from interface io.camunda.client.api.command.CommandWithTenantStep
DEFAULT_TENANT_IDENTIFIER -
Method Summary
Modifier and TypeMethodDescriptionbackoffSupplier(BackoffSupplier backoffSupplier) Sets the backoff supplier.fetchVariables(String... fetchVariables) Set a list of variable names which should be fetched on job activation.fetchVariables(List<String> fetchVariables) Set a list of variable names which should be fetched on job activation.jobExceptionHandler(JobExceptionHandler jobExceptionHandler) Sets the job exception handler to use for this worker.maxJobsActive(int maxJobsActive) Set the maximum number of jobs which will be exclusively activated for this worker at the same time.metrics(JobWorkerMetrics metrics) Sets the job worker metrics implementation to use.Set the name of the worker owner.open()Open the worker and start to work on available tasks.pollInterval(Duration pollInterval) Set the maximal interval between polling for new jobs.requestTimeout(Duration requestTimeout) Set the request timeout for activate job request used to poll for new job.streamEnabled(boolean isStreamEnabled) Opt-in feature flag to enable job streaming.streamInactivityTimeout(Duration timeout) If streaming is enabled, sets the maximum duration the worker will wait without receiving any job on the open stream before cancelling and recreating it.streamNoJobsBackoffSupplier(BackoffSupplier streamNoJobsBackoffSupplier) Sets the job activation backoff supplier to be used when polling yields no jobs, when streaming is enabled.streamTimeout(Duration timeout) If streaming is enabled, sets a maximum lifetime for a given stream.tenantFilter(TenantFilter tenantFilter) The behavior to adopt when filtering jobs during activation by this worker.timeout(long timeout) Set the time for how long a job is exclusively assigned for this worker.Set the time for how long a job is exclusively assigned for this worker.withLease(boolean withLease) Activate the jobs polled by this worker with a lease.Methods inherited from interface io.camunda.client.api.command.CommandWithOneOrMoreTenantsStep
tenantId, tenantIds, tenantIds
-
Method Details
-
timeout
Set the time for how long a job is exclusively assigned for this worker.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.
- Parameters:
timeout- the time in milliseconds- Returns:
- the builder for this worker
-
timeout
Set the time for how long a job is exclusively assigned for this worker.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.
- Parameters:
timeout- the time as duration (e.g. "Duration.ofMinutes(5)")- Returns:
- the builder for this worker
-
name
Set the name of the worker owner.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.
- Parameters:
workerName- the name of the worker (e.g. "payment-service")- Returns:
- the builder for this worker
-
maxJobsActive
Set the maximum number of jobs which will be exclusively activated for this worker at the same time.This is used to control the backpressure of the worker. When the maximum is reached then the worker will stop activating new jobs in order to not overwhelm the client and give other workers the chance to work on the jobs. The worker will try to activate new jobs again when jobs are completed (or marked as failed).
If no maximum is set then the default, from the
CamundaClientConfiguration, is used.Considerations:
- A greater value can avoid situations in which the client waits idle for the broker to provide more jobs. This can improve the worker's throughput.
- The memory used by the worker is linear with respect to this value.
- The job's timeout starts to run down as soon as the broker pushes the job. Keep in mind
that the following must hold to ensure fluent job handling:
time spent in queue + time job handler needs until job completion invalid input: '<' job timeout
- Parameters:
maxJobsActive- the maximum jobs active by this worker- Returns:
- the builder for this worker
-
pollInterval
Set the maximal interval between polling for new jobs.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
CamundaClientConfiguration- Parameters:
pollInterval- the maximal interval to check for new jobs- Returns:
- the builder for this worker
-
requestTimeout
Set the request timeout for activate job request used to poll for new job.If no request timeout is set then the default is used from the
CamundaClientConfigurationNOTE: the request time out defined here is only applied to the activate jobs command, i.e. to polling for jobs, and is not applied to the job stream; use
streamTimeout(Duration)for that.- Parameters:
requestTimeout- the request timeout for activate jobs request- Returns:
- the builder for this worker
-
fetchVariables
Set a list of variable names which should be fetched on job activation.The jobs which are activated by this worker will only contain variables from this list.
This can be used to limit the number of variables of the activated jobs.
- Parameters:
fetchVariables- list of variables names to fetch on activation- Returns:
- the builder for this worker
-
fetchVariables
Set a list of variable names which should be fetched on job activation.The jobs which are activated by this worker will only contain variables from this list.
This can be used to limit the number of variables of the activated jobs.
- Parameters:
fetchVariables- list of variables names to fetch on activation- Returns:
- the builder for this worker
-
withLease
Activate the jobs polled by this worker with a lease. When enabled, each activated job is assigned a distinct lease token, fencing the complete, fail, and throw-error commands against a superseded activation of the same job.Only applies to the polling path. If not set, jobs are activated without a lease.
- Parameters:
withLease- whether to activate the jobs with a lease- Returns:
- the builder for this worker
-
backoffSupplier
Sets the backoff supplier. The supplier is called to determine the retry delay after each failed request; the worker then waits until the returned delay has elapsed before sending the next request. Note that this is used only when activating jobs - failures in theJobHandlershould be handled there, and retried there if need be.By default, the supplier uses exponential back off, with an upper bound of 5 seconds. The exponential backoff can be easily configured using
BackoffSupplier.newBackoffBuilder().- Parameters:
backoffSupplier- supplies the retry delay after a failed request- Returns:
- the builder for this worker
-
streamNoJobsBackoffSupplier
JobWorkerBuilderStep1.JobWorkerBuilderStep3 streamNoJobsBackoffSupplier(BackoffSupplier streamNoJobsBackoffSupplier) Sets the job activation backoff supplier to be used when polling yields no jobs, when streaming is enabled. The supplier is called to determine the backoff delay after a successful poll request with no activated jobs when job streaming is enabled; the worker then waits until the returned delay has elapsed before sending the next poll request.Note, this is used only when streaming is enabled.
By default, the supplier uses exponential back off, with an upper bound of 1 minute. The exponential backoff can be easily configured using
BackoffSupplier.newBackoffBuilder().- Parameters:
streamNoJobsBackoffSupplier- supplies the backoff delay after a successful poll request- Returns:
- the builder for this worker
-
streamEnabled
Opt-in feature flag to enable job streaming. If set as enabled, the job worker will use a mix of streaming and polling to activate jobs. A long living stream will be opened onto which jobs will be eagerly pushed, and the polling mechanism will be used strictly to fetch jobs created before any streams were opened.If the stream is closed, e.g. the server closed the connection, was restarted, etc., it will be immediately recreated as long as the worker is opened.
- Returns:
- the builder for this worker
-
streamTimeout
If streaming is enabled, sets a maximum lifetime for a given stream. Once this timeout is reached, the stream is closed, such that no more jobs are activated and received. If the worker is still open, then it will immediately open a new stream.With no timeout, the stream will live as long as the client, or until the server closes the connection.
It's recommended to set a relatively long timeout, to allow for streams to load balance properly across your gateways.
- Parameters:
timeout- a timeout, after which the stream is recreated- Returns:
- the builder for this worker
-
streamInactivityTimeout
If streaming is enabled, sets the maximum duration the worker will wait without receiving any job on the open stream before cancelling and recreating it. The timer is reset every time a job is received.This acts as an application-level liveness check on top of the transport-level HTTP/2 keepalive: it detects silent stalls where the transport is healthy but the stream is no longer producing jobs (for example, because an intermediary proxy keeps the socket warm while the broker-side handler has stopped pushing).
Must be strictly less than
streamTimeout(Duration)when both are configured. Passnullto disable the inactivity watchdog.- Parameters:
timeout- duration of inactivity after which the stream is cancelled and recreated, ornullto disable- Returns:
- the builder for this worker
-
metrics
Sets the job worker metrics implementation to use. SeeJobWorkerMetricsfor more. Defaults toJobWorkerMetrics.noop(), an implementation which simply does nothing.- Parameters:
metrics- the implementation to use- Returns:
- the builder for this worker
-
jobExceptionHandler
JobWorkerBuilderStep1.JobWorkerBuilderStep3 jobExceptionHandler(JobExceptionHandler jobExceptionHandler) Sets the job exception handler to use for this worker. SeeJobExceptionHandlerfor more. Defaults toCamundaClientBuilder.defaultJobWorkerExceptionHandler(JobExceptionHandler).- Parameters:
jobExceptionHandler- the retry backoff supplier to use- Returns:
- the builder for this worker
-
tenantFilter
The behavior to adopt when filtering jobs during activation by this worker. SeeTenantFilterfor possible values. Defaults toio.camunda.client.CamundaClientBuilder#defaultJobWorkerTenantFilter(tenantFilter)}.invalid @link
{@link *- Specified by:
tenantFilterin interfaceCommandWithOneOrMoreTenantsStep<JobWorkerBuilderStep1.JobWorkerBuilderStep3>- Parameters:
tenantFilter- the default filter to use for all workers- Returns:
- the builder for this command with the tenant filter specified
-
open
JobWorker open()Open the worker and start to work on available tasks.- Returns:
- the worker
-