fullcube / camunda-worker-node

Implement external task workers for Camunda BPM in NodeJS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

camunda-worker-node

Implement external task workers for Camunda BPM in NodeJS.

Compatible with Camunda BPM 7.5+.

Summary

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" />

Extend Workers

Workers may be extended via the use config parameter.

Workers(engineEndpoint, {
  use: [
    Logger,
    Backoff
  ]
});

Existing Extensions

  • Logger - adds verbose logging of what is going on
  • Backoff - increase polling intervals if the engine endpoint is temporarily unavailable

Dynamically Unregister a Worker

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();

Installation

npm i --save camunda-worker-node

Develop

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.

License

MIT

About

Implement external task workers for Camunda BPM in NodeJS.


Languages

Language:JavaScript 100.0%