Zeebe worker for script evaluation
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.ci
src
.gitignore
CODE_OF_CONDUCT.md
LICENSE
README.md
pom.xml

README.md

zeebe-script-worker

This is a Zeebe worker to evaluate scripts. Scripts are useful to create/modify the payload, to do (simple) calculations or for prototyping.

  • the worker is registered for the type script
  • required custom headers:
    • language (String) - the name of the script language
    • script (String) - the script to evaluate
  • output payload contains result - the result of the evaluation

Available script languages:

This is a community project meant for playing around with Zeebe. It is not officially supported by the Zeebe Team (i.e. no gurantees). Everybody is invited to contribute!

Usage

The service task:

<bpmn:serviceTask id="scripting" name="Evaluate the Script">
  <bpmn:extensionElements>
    <zeebe:taskDefinition type="script" />
    <zeebe:taskHeaders>
      <zeebe:header key="language" value="javascript" />
      <zeebe:header key="script" value="a + b" />
    </zeebe:taskHeaders>
  </bpmn:extensionElements>
</bpmn:serviceTask>

The job's payload:

{ "a": 2,
  "b": 3 }

The job's result payload:

{ "result": 5 }

How to build

Build with Maven

mvn clean install

How to run

Execute the JAR file via

java -jar target/zeebe-script-worker-{VERSION}.jar

How to configure

The worker can be configured via environment variables or a properties file application.properties.

zeebe.client.broker.contactPoint=127.0.0.1:26500

Examples

Some examples for common use cases:

Single Value

JavaScript:

'url?id=' + id

Result:

{"result": "url?id=123"}

Complex Value

JavaScript:

result = {};
result.orderId = id;
result.price = price * 1.20;
result;

Groovy:

[orderId:id,
 price:price * 1.20 ]

FEEL:

{orderId:id,
 price:price * 1.20 }

Result:

{"result": {
 "orderId": 123,
 "price": 120.0 }}

Aggregation

Jobs' payload:

{"order": {
 "id": 123,
 "items": [
  {"id":"i1", "price":5.99},
  {"id":"i2", "price":29.99},
  {"id":"i3", "price":10.00}
 ]}}

FEEL:

sum(order.items.price)                                    
// result: 45.98

some item in order.items satisfies item.price > 20.00     
// result: true

order.items[price >= 10.00]                               
// result: [{"id":"i2", "price":29.99}, {"id":"i3", "price":10.00}]

Code of Conduct

This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to code-of-conduct@zeebe.io.