camunda-external-task-client
Implement your BPMN Service Task in
NodeJS.
This package is an ECMAScript module (ESM) and provides no CommonJS exports.
NodeJS >= v18 is required
Installing
npm install -s camunda-external-task-client-js
Or:
yarn add camunda-external-task-client-js
Usage
- Make sure to have Camunda running.
- Create a simple process model with an External Service Task and define the topic as 'topicName'.
- Deploy the process to the Camunda Platform engine.
- In your NodeJS script:
import { Client, logger } from "camunda-external-task-client-js";
const config = { baseUrl: "http://localhost:8080/engine-rest", use: logger };
const client = new Client(config);
client.subscribe("creditScoreChecker", async function({ task, taskService }) {
await taskService.complete(task);
});
Note: Although the examples used in this documentation use async await for handling asynchronous calls, you
can also use Promises to achieve the same results.
About External Tasks
External Tasks are service tasks whose execution differs particularly from the execution of other service tasks (e.g. Human Tasks).
The execution works in a way that units of work are polled from the engine before being completed.
camunda-external-task-client.js allows you to create easily such client in NodeJS.
Features
Done through polling.
client.subscribe("topicName", async function({ task, taskService }) {
await taskService.complete(task);
});
client.subscribe("topicName", async function({ task, taskService }) {
await taskService.handleFailure(task, {
errorMessage: "some failure message",
errorDetails: "some details",
retries: 1,
retryTimeout: 1000
});
});
client.subscribe("topicName", async function({ task, taskService }) {
const variables = new Variables().set('date', new Date());
await taskService.handleBpmnError(task, "BPMNError_Code", "Error message", variables);
});
client.subscribe("topicName", async function({ task, taskService }) {
await taskService.extendLock(task, 5000);
});
client.subscribe("topicName", async function({ task, taskService }) {
await taskService.unlock(task);
});
client.subscribe("topicName", async function({ task, taskService }) {
await taskService.lock(task, 5000);
});
Exchange Process & Local Task Variables
import { Variables } from "camunda-external-task-client-js";
client.subscribe("topicName", async function({ task, taskService }) {
const score = task.variables.get("score");
const processVariables = new Variables();
processVariables.set("winning", score > 5);
const localVariables = new Variables();
localVariables.set("winningDate", new Date());
await taskService.complete(task, processVariables, localVariables);
});
API
Contributing
Have a look at our contribution guide for how to contribute to this repository.
Help and support
License
The source files in this repository are made available under the Apache License Version 2.0.