Skip to content

camunda-platform-7-custom-batch#

The goal of this camunda extension is to provide an simple way of using the camunda batch functionality. Camunda Batch could be used to split a huge workload into small asynchronous jobs. With this extension, we want to open the camunda batch functionality to everyone.

Why should I use this extension#

Camunda batch is really cool for offloading huge workload into small asynchronous pieces of work. E.g.:

  • Unclaiming / Updating a huge list of camunda tasks
  • Call APIs with batches of data
  • Distribution of emails
  • Technical stuff like clean-up

Get started#

The extension will be published on maven central, so if you are using maven, just add the dependency:

Maven Users:

<dependency>
  <groupId>io.holunda.c7</groupId>
  <artifactId>c7-custom-batch-core</artifactId>
</dependency>

Gradle Users:

compile("io.holunda.c7:c7-custom-batch-core")

First you have to define an own job handler for working on the single batch data:

@Component
public class PrintStringBatchJobHandler extends CustomBatchJobHandler<String> {
  @Override
  public void execute(List<String> data, CommandContext commandContext) {
      data.forEach(dataEntry -> logger.info("Work on data entry: " + dataEntry));
  }

  @Override
  public String getType() {
      return "print-string-batch-handler";
  }
}

Next you have to notify the engine about this job handler, e.g. with spring-boot:

@Bean
public ProcessEnginePlugin customBatchHandlerPlugin(PrintStringBatchJobHandler printStringBatchJobHandler) {
  return CustomBatchHandlerPlugin.of(printStringBatchJobHandler);
}

Finally, the creation of the batch itself:

CustomBatchBuilder.of(listOfStringData)
  .jobHandler(printStringBatchJobHandler)
  .create();

Or with more configuration:

CustomBatchBuilder.of(listOfStringData)
  .configuration(engineConfiguration)
  .jobHandler(printStringBatchJobHandler)
  .jobsPerSeed(10)
  .jobPriority(0L)
  .invocationsPerBatchJob(5)
  .exclusive(true)
  .create(engineConfiguration.getCommandExecutorTxRequired());

Note: The batch jobPriority is only considered when using Job Executor with the corresponding Acquisition Strategy jobExecutorAcquireByPriority. (see camunda documentation) The seed and monitor jobs receive the same priority as the batch.

Resources#