Implement external task workers for Camunda BPM in NodeJS.
Compatible with Camunda BPM 7.5+.
This library provides you with a simple API to implement external tasks for the Camunda process engine with NodeJS.
var Workers = require('camunda-worker-node');
var engineEndpoint = 'http://localhost:8080/engine-rest';
var workers = Workers(engineEndpoint, {
workerId: 'some-worker-id'
});
// a worker may access request, access and modify process variables
workers.registerWorker('work:A', [ 'numberVar' ], function(context, callback) {
var newNumber = context.variables.numberVar + 1;
// node style callback (err, result)
callback(null, {
variables: {
numberVar: newNumber
}
});
});
// a worker can handle errors, too
workers.registerWorker('work:B', function(context, callback) {
// report an error, if things go awry
callback(new Error('no work done'));
});
// shutdown the workers instance with the application
workers.shutdown();
Make sure you defined the external tasks in the process diagram before:
<bpmn:serviceTask
id="Task_A"
camunda:type="external"
camunda:topicName="work:A" />
Workers may be extended via the use
config parameter.
Workers(engineEndpoint, {
use: [
Logger,
Backoff
]
});
Logger
- adds verbose logging of what is going onBackoff
- increase polling intervals if the engine endpoint is temporarily unavailable
It is possible to dynamically unregister a worker any time.
var worker = workers.registerWorker('someTopic', function(context, callback) {
// do work
callback(null);
});
// later
worker.remove();
npm i --save camunda-worker-node
npm install
npm test
Hint: You need a Camunda BPM REST API exposed on localhost:8080/engine-rest
for the tests to pass. An easy way to get it up running is via Docker.
MIT