Skip to content
Implement your BPMN Service Task in NodeJS.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__mocks__ chore(maintain): improve test coverage Mar 20, 2018
docs feat(subscribe): add possibility to filter tasks by tenant Oct 15, 2018
examples fix(examples): fix package.json of order example Nov 23, 2018
lib feat(subscribe): add possibility to filter tasks by tenant Oct 15, 2018
test
.eslintrc chore(style): add prettier for code styling Apr 4, 2018
.gitignore feat(complete): add complete functionality & tests for clients Feb 27, 2018
.npmignore chore(release): adjust changelog Nov 23, 2018
.travis.yml
CHANGELOG.md
LICENSE
README.md docs(handleBpmnError): update docs for handleBpmnError Aug 30, 2018
index.js chore(docs): update docs for latest release Apr 11, 2018
package-lock.json chore(package-lock): adjust package-lock Nov 23, 2018
package.json chore(release): bump to 1.1.1 Nov 23, 2018
yarn.lock chore(style): add prettier for code styling Apr 4, 2018

README.md

camunda-external-task-client

Build Status

Implement your BPMN Service Task in NodeJS.

NodeJS >= v8.9.4 is required

Installing

npm install -s camunda-external-task-client-js

Or:

yarn add camunda-external-task-client-js

Usage

  1. Make sure to have Camunda running.
  2. Create a simple process model with an External Service Task and define the topic as 'topicName'.
  3. Deploy the process to the Camunda BPM engine.
  4. In your NodeJS script:
const { Client, logger } = require("camunda-external-task-client-js");

// configuration for the Client:
//  - 'baseUrl': url to the Workflow Engine
//  - 'logger': utility to automatically log important events
const config = { baseUrl: "http://localhost:8080/engine-rest", use: logger };

// create a Client instance with custom configuration
const client = new Client(config);

// susbscribe to the topic: 'creditScoreChecker'
client.subscribe("creditScoreChecker", async function({ task, taskService }) {
  // Put your business logic
  // complete the task
  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

Fetch and Lock

Done through polling.

Complete

// Susbscribe to the topic: 'topicName'
client.subscribe("topicName", async function({ task, taskService }) {
  // Put your business logic
  // Complete the task
  await taskService.complete(task);
});

Handle Failure

// Susbscribe to the topic: 'topicName'
client.subscribe("topicName", async function({ task, taskService }) {
  // Put your business logic
  // Handle a Failure
  await taskService.handleFailure(task, {
    errorMessage: "some failure message",
    errorDetails: "some details",
    retries: 1,
    retryTimeout: 1000
  });

});

Handle BPMN Error

// Susbscribe to the topic: 'topicName'
client.subscribe("topicName", async function({ task, taskService }) {
  // Put your business logic

  // Create some variables
  const variables = new Variables().set('date', new Date());

  // Handle a BPMN Failure
  await taskService.handleBpmnError(task, "BPMNError_Code", "Error message", variables);
});

Extend Lock

// Susbscribe to the topic: 'topicName'
client.subscribe("topicName", async function({ task, taskService }) {
  // Put your business logic
  // Extend the lock time
  await taskService.extendLock(task, 5000);
});

Unlock

// Susbscribe to the topic: 'topicName'
client.subscribe("topicName", async function({ task, taskService }) {
  // Put your business logic
  // Unlock the task
  await taskService.unlock(task);
});

Exchange Process & Local Task Variables

const { Variables } = require("camunda-external-task-client-js");

client.subscribe("topicName", async function({ task, taskService }) {
  // get the process variable 'score'
  const score = task.variables.get("score");

  // set a process variable 'winning'
  const processVariables = new Variables();
  processVariables.set("winning", score > 5);

  // set a local variable 'winningDate'
  const localVariables = new Variables();
  localVariables.set("winningDate", new Date());

  // complete the task
  await taskService.complete(task, processVariables, localVariables);
});

API

License

Unless otherwise specified this project is licensed under Apache License Version 2.0.

You can’t perform that action at this time.