Camunda Node.js External Task Client 0.1.1 Released

By
  • Blog
  • >
  • Camunda Node.js External Task Client 0.1.1 Released
TOPICS

30 Day Free Trial

Bring together legacy systems, RPA bots, microservices and more with Camunda

Sign Up for Camunda Content

Get the latest on Camunda features, events, top trends, and more.

TRENDING CONTENT

We recently published the first alpha release of camunda-external-task-client-js,
an NPM module that makes it possible to handle your BPMN Service Tasks in Node.js.

Today, a new alpha release is ready, bringing up major features that revolve around easily exchanging process variables between
Service Tasks and the Workflow Engine.

The feature set includes:

  • Accessing single/all variables
  • Creating/Updating single or multiple variables
  • Support for primitive (e.g. Integer) and complex variable types (e.g. JSON)

Let’s walk through a basic example to showcase some of these features:

Example

A Workflow for Granting Loans

1. Running Camunda

First, make sure to have Camunda running.

2. Deploying the Workflow

Download the following model
and deploy it using the Camunda Modeler.

3. Installing the NPM package

Install camunda-external-task-client-js from npm using:

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

Or:

yarn add camunda-external-task-client-js

4. Consuming Service Tasks in Node.js

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: 'https://localhost:8080/engine-rest', use: logger };

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

// create a handler for the task
const handler = async({ task, taskService }) => {
  // get task variable 'defaultScore'
  const defaultScore = task.variables.get('defaultScore');

  // set task variable 'creditScores'
  task.variables.set('creditScores', [defaultScore, 9, 1, 4, 10]);

  // complete the task
  try {
    await taskService.complete(task);
    console.log('I completed my task successfully!!');
  } catch (e) {
    console.error(`Failed completing my task, ${e}`);
  }
};

// subscribe to the topic 'creditScoreChecker' & provide the created handler
client.subscribe('creditScoreChecker', handler);

The output should be:

polling
✓ subscribed to topic creditScoreChecker
polling
✓ polled 10 tasks
✓ completed task 897ce191-2dea-11e8-a9c0-66b11439c29a

Documentation & More Detailed Examples

The main goal of this post is to show a basic usage of the new alpha release of camunda-external-task-client-js.
To find out about the full range of features, you can check the documentation
or a more in-depth example.

Feedback

Your feedback is extremely important, so don’t hesitate to share it with us by:

Try All Features of Camunda

Related Content

Learn how to get started with automated underwriting, what the benefits are and why automation in underwriting is important.
An integral part of process orchestration is process automation—get those repeatable, well-understood tasks that don't require complex decision-making on autopilot!
Enhance your business's operational efficiency with business process management, and streamline your workflows to reduce cost and minimize risk.