use of io.camunda.zeebe.config.WorkerCfg in project zeebe by camunda-cloud.
the class Worker method run.
@Override
public void run() {
final WorkerCfg workerCfg = appCfg.getWorker();
final String jobType = workerCfg.getJobType();
final long completionDelay = workerCfg.getCompletionDelay().toMillis();
final var variables = readVariables(workerCfg.getPayloadPath());
final BlockingQueue<Future<?>> requestFutures = new ArrayBlockingQueue<>(10_000);
final BlockingDeque<DelayedCommand> delayedCommands = new LinkedBlockingDeque<>(10_000);
final ZeebeClient client = createZeebeClient();
printTopology(client);
final JobWorker worker = client.newWorker().jobType(jobType).handler((jobClient, job) -> {
final var command = jobClient.newCompleteCommand(job.getKey()).variables(variables);
if (workerCfg.isCompleteJobsAsync()) {
delayedCommands.addLast(new DelayedCommand(Instant.now().plusMillis(completionDelay), command));
} else {
try {
Thread.sleep(completionDelay);
} catch (Exception e) {
e.printStackTrace();
}
requestFutures.add(command.send());
}
}).open();
final ResponseChecker responseChecker = new ResponseChecker(requestFutures);
responseChecker.start();
final var asyncJobCompleter = new DelayedCommandSender(delayedCommands, requestFutures);
if (workerCfg.isCompleteJobsAsync()) {
asyncJobCompleter.start();
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
worker.close();
client.close();
asyncJobCompleter.close();
responseChecker.close();
}));
}
use of io.camunda.zeebe.config.WorkerCfg in project zeebe by zeebe-io.
the class Worker method createZeebeClient.
private ZeebeClient createZeebeClient() {
final WorkerCfg workerCfg = appCfg.getWorker();
final ZeebeClientBuilder builder = ZeebeClient.newClientBuilder().gatewayAddress(appCfg.getBrokerUrl()).numJobWorkerExecutionThreads(workerCfg.getThreads()).defaultJobWorkerName(workerCfg.getWorkerName()).defaultJobTimeout(workerCfg.getCompletionDelay().multipliedBy(6)).defaultJobWorkerMaxJobsActive(workerCfg.getCapacity()).defaultJobPollInterval(workerCfg.getPollingDelay()).withProperties(System.getProperties()).withInterceptors(monitoringInterceptor);
if (!appCfg.isTls()) {
builder.usePlaintext();
}
return builder.build();
}
use of io.camunda.zeebe.config.WorkerCfg in project zeebe by zeebe-io.
the class Worker method run.
@Override
public void run() {
final WorkerCfg workerCfg = appCfg.getWorker();
final String jobType = workerCfg.getJobType();
final long completionDelay = workerCfg.getCompletionDelay().toMillis();
final var variables = readVariables(workerCfg.getPayloadPath());
final BlockingQueue<Future<?>> requestFutures = new ArrayBlockingQueue<>(10_000);
final BlockingDeque<DelayedCommand> delayedCommands = new LinkedBlockingDeque<>(10_000);
final ZeebeClient client = createZeebeClient();
printTopology(client);
final JobWorker worker = client.newWorker().jobType(jobType).handler((jobClient, job) -> {
final var command = jobClient.newCompleteCommand(job.getKey()).variables(variables);
if (workerCfg.isCompleteJobsAsync()) {
delayedCommands.addLast(new DelayedCommand(Instant.now().plusMillis(completionDelay), command));
} else {
try {
Thread.sleep(completionDelay);
} catch (Exception e) {
e.printStackTrace();
}
requestFutures.add(command.send());
}
}).open();
final ResponseChecker responseChecker = new ResponseChecker(requestFutures);
responseChecker.start();
final var asyncJobCompleter = new DelayedCommandSender(delayedCommands, requestFutures);
if (workerCfg.isCompleteJobsAsync()) {
asyncJobCompleter.start();
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
worker.close();
client.close();
asyncJobCompleter.close();
responseChecker.close();
}));
}
use of io.camunda.zeebe.config.WorkerCfg in project zeebe by camunda-cloud.
the class Worker method createZeebeClient.
private ZeebeClient createZeebeClient() {
final WorkerCfg workerCfg = appCfg.getWorker();
final ZeebeClientBuilder builder = ZeebeClient.newClientBuilder().gatewayAddress(appCfg.getBrokerUrl()).numJobWorkerExecutionThreads(workerCfg.getThreads()).defaultJobWorkerName(workerCfg.getWorkerName()).defaultJobTimeout(workerCfg.getCompletionDelay().multipliedBy(6)).defaultJobWorkerMaxJobsActive(workerCfg.getCapacity()).defaultJobPollInterval(workerCfg.getPollingDelay()).withProperties(System.getProperties()).withInterceptors(monitoringInterceptor);
if (!appCfg.isTls()) {
builder.usePlaintext();
}
return builder.build();
}
use of io.camunda.zeebe.config.WorkerCfg in project zeebe by camunda.
the class Worker method createZeebeClient.
private ZeebeClient createZeebeClient() {
final WorkerCfg workerCfg = appCfg.getWorker();
final ZeebeClientBuilder builder = ZeebeClient.newClientBuilder().gatewayAddress(appCfg.getBrokerUrl()).numJobWorkerExecutionThreads(workerCfg.getThreads()).defaultJobWorkerName(workerCfg.getWorkerName()).defaultJobTimeout(workerCfg.getCompletionDelay().multipliedBy(6)).defaultJobWorkerMaxJobsActive(workerCfg.getCapacity()).defaultJobPollInterval(workerCfg.getPollingDelay()).withProperties(System.getProperties()).withInterceptors(monitoringInterceptor);
if (!appCfg.isTls()) {
builder.usePlaintext();
}
return builder.build();
}
Aggregations