Gathering detailed insights and metrics for @digitaltg/gnspd-camunda-external-task-client-js
Gathering detailed insights and metrics for @digitaltg/gnspd-camunda-external-task-client-js
Gathering detailed insights and metrics for @digitaltg/gnspd-camunda-external-task-client-js
Gathering detailed insights and metrics for @digitaltg/gnspd-camunda-external-task-client-js
npm install @digitaltg/gnspd-camunda-external-task-client-js
Typescript
Module System
Node Version
NPM Version
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Latest Version
1.1.1
Package Id
@digitaltg/gnspd-camunda-external-task-client-js@1.1.1
Unpacked Size
243.62 kB
Size
78.22 kB
File Count
50
NPM Version
10.8.2
Node Version
18.20.3
Published on
Feb 04, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Note: this is a customized version of camunda-external-task-client-js, available on the following GitHub repository: https://github.com/camunda/camunda-external-task-client-js
Implement your BPMN Service Task in NodeJS.
This package is an ECMAScript module (ESM) and provides no CommonJS exports.
NodeJS >= v18 is required
1npm install -s @digitaltg/gnspd-camunda-external-task-client-js
Or:
1yarn add @digitaltg/gnspd-camunda-external-task-client-js
1import { Client, logger } from "@digitaltg/gnspd-camunda-external-task-client-js"; 2 3// Configuration for the Client: 4// - 'baseUrl': URL to the Process Engine 5// - 'useRabbitMQ': Enable RabbitMQ integration 6// - 'rabbitMQ': RabbitMQ settings 7// - 'url': Connection URL for RabbitMQ 8// - 'exchange': Exchange name for Camunda communication 9// - 'onTaskPushed': Callback when a task is pushed 10// - 'onTaskFail': Callback when a task fails 11// - 'use': Utility to automatically log important events 12 13const config = { 14 baseUrl: "http://172.24.208.1:8080/engine-rest", 15 useRabbitMQ: true, 16 rabbitMQ: { 17 url: "amqp://localhost:5672", 18 exchange: "camunda-exchange", 19 onTaskPushed: (task) => { 20 console.log(task); 21 }, 22 onTaskFail: (error) => { 23 console.log(error); 24 }, 25 }, 26 use: logger, 27};
Note: If useRabbit is enabled (true), there's no need to perform a subscribe, as all tasks will be sent to the RabbitMQ queue. All you need to do is specify the desired topic.
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.
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.
Done through polling.
1// Susbscribe to the topic: 'topicName' 2client.subscribe("topicName", async function({ task, taskService }) { 3 // Put your business logic 4 // Complete the task 5 await taskService.complete(task); 6}); 7
1import amqp from "amqplib"; 2 3const config = { 4 url: "amqp://localhost:5672", 5 exchange: "camunda-exchange", 6 queue: "camunda-tasks", 7}; 8 9async function startConsumer() { 10 try { 11 // connect to RabbitMQ 12 const connection = await amqp.connect(config.url); 13 14 // Create a communication channel 15 const channel = await connection.createChannel(); 16 17 // Declaration of exchange in “direct” mode 18 await channel.assertExchange(config.exchange, "direct", { 19 durable: true, 20 }); 21 22 // Queue declaration 23 await channel.assertQueue(config.queue, { 24 durable: true, 25 }); 26 27 // Link the queue to the exchange using the “task” routing key 28 await channel.bindQueue(config.queue, config.exchange, "task"); 29 30 await channel.consume(config.queue, async (msg) => { 31 if (msg !== null) { 32 try { 33 // Extract message data 34 const taskData = JSON.parse(msg.content.toString()); 35 36 // Confirms receipt and processing of message 37 channel.ack(msg); 38 console.log("✅ Message traité et acquitté"); 39 } catch (error) { 40 console.error("❌ Erreur lors du traitement du message:", error); 41 42 // Requeues the message for a new attempt 43 channel.nack(msg, false, true); 44 } 45 } 46 }); 47 48 } catch (error) { 49 console.error("❌ Erreur de connexion:", error); 50 process.exit(1); 51 } 52}
Note: : channel.ack(msg) - Permanently removes the message from the queue - Use when the message has been fully processed without error and you want to remove the message from the queue. channel.nack(msg) - Use if you want to return the message to the queue.
1// Susbscribe to the topic: 'topicName'
2client.subscribe("topicName", async function({ task, taskService }) {
3 // Put your business logic
4 // Handle a Failure
5 await taskService.handleFailure(task, {
6 errorMessage: "some failure message",
7 errorDetails: "some details",
8 retries: 1,
9 retryTimeout: 1000
10 });
11
12});
1// Susbscribe to the topic: 'topicName' 2client.subscribe("topicName", async function({ task, taskService }) { 3 // Put your business logic 4 5 // Create some variables 6 const variables = new Variables().set('date', new Date()); 7 8 // Handle a BPMN Failure 9 await taskService.handleBpmnError(task, "BPMNError_Code", "Error message", variables); 10});
1// Susbscribe to the topic: 'topicName' 2client.subscribe("topicName", async function({ task, taskService }) { 3 // Put your business logic 4 // Extend the lock time 5 await taskService.extendLock(task, 5000); 6});
1// Susbscribe to the topic: 'topicName' 2client.subscribe("topicName", async function({ task, taskService }) { 3 // Put your business logic 4 // Unlock the task 5 await taskService.unlock(task); 6});
1// Susbscribe to the topic: 'topicName' 2client.subscribe("topicName", async function({ task, taskService }) { 3 // Task is locked by default 4 // Put your business logic, unlock the task or let the lock expire 5 6 // Lock a task again 7 await taskService.lock(task, 5000); 8});
1import { Variables } from "@digitaltg/gnspd-camunda-external-task-client-js"; 2 3client.subscribe("topicName", async function({ task, taskService }) { 4 // get the process variable 'score' 5 const score = task.variables.get("score"); 6 7 // set a process variable 'winning' 8 const processVariables = new Variables(); 9 processVariables.set("winning", score > 5); 10 11 // set a local variable 'winningDate' 12 const localVariables = new Variables(); 13 localVariables.set("winningDate", new Date()); 14 15 // complete the task 16 await taskService.complete(task, processVariables, localVariables); 17});
Have a look at our contribution guide for how to contribute to this repository.
The source files in this repository are made available under the Apache License Version 2.0.
No vulnerabilities found.
No security vulnerabilities found.