@5minds/processcube_engine_client
Advanced tools
Comparing version 4.3.1 to 4.3.2-hotfix-094bc8-ll1ztrh2
@@ -25,3 +25,3 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
Messages.CallbackTypes = callbackTypes; | ||
})(Messages = exports.Messages || (exports.Messages = {})); | ||
})(Messages || (exports.Messages = Messages = {})); | ||
__exportStar(IExternalTaskWorker_1, exports); | ||
@@ -28,0 +28,0 @@ __exportStar(RestSettings_1, exports); |
@@ -26,3 +26,3 @@ "use strict"; | ||
Messages.CallbackTypes = callbackTypes; | ||
})(Messages = exports.Messages || (exports.Messages = {})); | ||
})(Messages || (exports.Messages = Messages = {})); | ||
__exportStar(require("./IExternalTaskWorker"), exports); | ||
@@ -29,0 +29,0 @@ __exportStar(require("./RestSettings"), exports); |
{ | ||
"name": "@5minds/processcube_engine_client", | ||
"version": "4.3.1", | ||
"version": "4.3.2-hotfix-094bc8-ll1ztrh2", | ||
"description": "Contains a typescript based client for accessing the Engine.", | ||
@@ -24,3 +24,3 @@ "main": "dist/commonjs/index.js", | ||
"dependencies": { | ||
"@5minds/processcube_engine_sdk": "3.3.0", | ||
"@5minds/processcube_engine_sdk": "3.3.2-hotfix-5e5851-ll1zhz20", | ||
"@types/socket.io": "^2.1.13", | ||
@@ -27,0 +27,0 @@ "@types/socket.io-client": "^1.4.36", |
250
README.md
# Engine Client.ts | ||
A client for communicating with the `Engine`. | ||
Ein NodeJS basierter Client zur Kommunikation mit der ProcessCube Engine. | ||
It is written in TypeScript and implemented in NodeJS. | ||
Codebeispiele zur Verwendung des Clients und der External Task Worker [finden sich hier](./samples). | ||
## Quick example | ||
## Schnelleinstieg | ||
```ts | ||
import {EngineClient} from '@5minds/processcube_engine_client'; | ||
import { EngineClient } from '@5minds/processcube_engine_client'; | ||
const engineUri = 'http://localhost:10560'; | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
const client = new EngineClient(engineUri); | ||
const processInstances = await client.processInstances.query({}); | ||
const processInstancesInCorrelation = await client.processInstances.query({ | ||
correlationid: 'my-correlation-id', | ||
}); | ||
``` | ||
console.log(processInstances); | ||
} | ||
## Wie kann ich den Client verwenden? | ||
run(); | ||
``` | ||
Man benötigt lediglich die URL der anzusteuernden Engine. | ||
Mit dieser lässt sich eine Instanz des Clients anlegen, die direkt verwendbar ist. | ||
## How to use the client | ||
Es gibt verschiedene Wege sich Clients anzulegen. | ||
You only need to provide an url to the `Engine` you want to access. | ||
After that, the client is ready to use. | ||
### EngineClient | ||
You can either create a single EngineClient, which exposes references to all other clients, | ||
Man kann eine Instanz des `EngineClients` direkt anlegen, welche die API der ProcessCube Engine vollständig abdeckt. | ||
```ts | ||
import {EngineClient} from '@5minds/processcube_engine_client'; | ||
import { EngineClient } from '@5minds/processcube_engine_client'; | ||
const engineUri = 'http://localhost:10560'; | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
const client = new EngineClient(engineUri); | ||
const processInstances = await client.processInstances.query({}, null, 0, 100); | ||
const processInstancesInCorrelation = await client.processInstances.query({ | ||
correlationid: 'my-correlation-id', | ||
}); | ||
``` | ||
console.log(processInstances); | ||
} | ||
### Client Factory | ||
run(); | ||
``` | ||
Oder man kann sich über die Client Factory einen feature-spezifischen Client anlegen, der nur einen besimmten fachlichen Aspekt der ProcessCube Engine abdeckt. | ||
or create multiple specific clients with the ClientFactory: | ||
Beispiel: | ||
```ts | ||
import {ClientFactory} from '@5minds/processcube_engine_client'; | ||
import { ClientFactory } from '@5minds/processcube_engine_client'; | ||
const engineUri = 'http://localhost:10560'; | ||
async function run() { | ||
const processInstanceClient = ClientFactory.createProcessInstanceClient(engineUri); | ||
const processInstanceClient = ClientFactory.createProcessInstanceClient(engineUri); | ||
const processInstances = await processInstanceClient.query({}, null, 0, 100); | ||
console.log(processInstances); | ||
} | ||
run(); | ||
const processInstances = await processInstanceClient.query({ | ||
correlationid: 'my-correlation-id', | ||
}); | ||
``` | ||
### Starting Process Instances | ||
Hier wird eine Client Instanz angelegt, welche lediglich die Interaktion mit Prozessinstanzen abdeckt. | ||
You can start new Process Instances through `processDefinitionsClient.startProcessInstance(parameters)` - | ||
Resolves right after the Process Instance was started | ||
## Anwendungsbeispiele | ||
Where `parameters` is an object that collects all startup parameters. | ||
Nachfolgend werden ein paar der am häufigsten verwendeten Use Cases demonstriert. | ||
The following parameters are required: | ||
- `processModelId`: The ID of the Process Model to execute | ||
- `startEventId`: The ID of the Start Event by which to start the Process Model. Optional, if the Process Model only has one Start Event. | ||
### Prozesse starten | ||
In addition, the following optional parameters are available: | ||
- `correlationId`: The ID of the correlation to which this Process Instance belongs. If not provided, it will be auto-generated | ||
- `initialToken`: The initial process token with which to start the Process Instance | ||
- `parentProcessInstanceId`: When the Process Instance is supposed to be the Subprocess of another Process Instance, | ||
this contains the ID of the parent Process Instance | ||
Das Starten von Prozessinstanzen kann über die `EngineClient.processModels` Fachlichkeit realisiert werden. | ||
or through | ||
Prozesse lassen sich auf mehrere Arten starten. | ||
`processDefinitionsClient.startProcessInstanceAndAwaitEndEvent(parameters)` - | ||
Resolves when the Process Instance has finished with any End Event | ||
#### Einfacher Prozessstart | ||
or through | ||
`processDefinitionsClient.startProcessInstanceAndAwaitSpecificEndEvent(parameters, endEventId)` - | ||
Resolves after the ProcessInstance has reached a specific End Event | ||
and has additionally the required endEventId parameter: | ||
- `endEventId`: The ID of the End Event to wait for | ||
Examples: | ||
#### Start Process Instance and wait for it to start | ||
```ts | ||
import {EngineClient} from '@5minds/processcube_engine_client'; | ||
import { EngineClient } from '@5minds/processcube_engine_client'; | ||
const engineUri = 'http://localhost:10560'; | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
const client = new EngineClient(engineUri); | ||
await client.processDefinitions.startProcessInstance({processModelId: 'myProcessModelId'}); | ||
} | ||
run(); | ||
await client.processModels.startProcessInstance({processModelId: 'myProcessModelId'}); | ||
``` | ||
#### Start Process Instance and wait for it to finish | ||
Die `processModelId` ist der einzige erforderliche Parameter für diesen Request. | ||
```ts | ||
import {EngineClient} from '@5minds/processcube_engine_client'; | ||
Der Client wartet in diesem Szenario nur, bis die Engine den _Start_ des Prozesses bestätigt hat. | ||
const engineUri = 'http://localhost:10560'; | ||
#### Konfigurierter Prozessstart | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
Neben der `processModelId` können folgende Paramter mitgegeben werden: | ||
- `startEventId`: Die ID des Start Events von welchem aus der Prozess losgehen soll | ||
- **Hinweis:** Bei Prozessen mit mehreren Start Events ist dieser Parameter ebenfalls erforderlich! | ||
- `correlationId`: Gibt an, in welcher Correlation die Prozessinstanz laufen soll | ||
- `initialToken`: Der JSON-formatierte Prozess-Token, den die Prozessinstanz zu beginn besitzen soll | ||
await client.processDefinitions.startProcessInstanceAndAwaitEndEvent({processModelId: 'myProcessModelId'}); | ||
} | ||
run(); | ||
``` | ||
#### Start Process Instance and wait for an End Event | ||
```ts | ||
import {EngineClient} from '@5minds/processcube_engine_client'; | ||
import { EngineClient } from '@5minds/processcube_engine_client'; | ||
const engineUri = 'http://localhost:10560'; | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
const client = new EngineClient(engineUri); | ||
await client.processDefinitions.startProcessInstanceAndAwaitSpecificEndEvent({processModelId: 'myProcessModelId'}, 'My_End_Event_1'); | ||
} | ||
run(); | ||
await client.processModels.startProcessInstance({ | ||
processModelId: 'myProcessModelId', | ||
startEventId: 'StartEvent_1', | ||
correlationId: 'MyCorrelatioNid', | ||
initialToken: { | ||
hello: 'world', | ||
}, | ||
}); | ||
``` | ||
#### Start Process Instance with custom payload and correlation ID | ||
#### Prozess starten und auf dessen Ende warten | ||
```ts | ||
import {EngineClient} from '@5minds/processcube_engine_client'; | ||
import { EngineClient } from '@5minds/processcube_engine_client'; | ||
const engineUri = 'http://localhost:10560'; | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
const client = new EngineClient(engineUri); | ||
await client.processDefinitions.startProcessInstance({ | ||
processModelId: 'myProcessModelId', | ||
correlationId: 'my_custom_correlation_id', | ||
initialToken: { | ||
hello: 'world', | ||
}, | ||
}); | ||
} | ||
run(); | ||
await client.processModels.startProcessInstanceAndAwaitEndEvent({processModelId: 'myProcessModelId'}); | ||
``` | ||
#### Start Process Instance as a sub process | ||
Hier wartet der Client, bis die Engine den Prozess bis zum Ende ausgeführt hat. | ||
```ts | ||
import {EngineClient} from '@5minds/processcube_engine_client'; | ||
Die Methode akzeptiert dieselben Parameter wie `processModels.startProcessInstance`. | ||
const engineUri = 'http://localhost:10560'; | ||
## Query UserTasks | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
Abfragen aller User Tasks eines bestimmten Prozesses, die sich in einem "suspended" State befinden: | ||
await client.processDefinitions.startProcessInstance({ | ||
processModelId: 'myProcessModelId', | ||
parentProcessInstanceId: 'Some-Other-Process-Instance-Id', | ||
}); | ||
} | ||
run(); | ||
``` | ||
### Code Samples | ||
You can find [executable code samples here](./samples/client) and [here](https://github.com/atlas-engine/ClientSamples/tree/develop/Client.ts). | ||
## Query UserTasks | ||
```ts | ||
import {EngineClient, DataModels} from '@5minds/processcube_engine_client'; | ||
import { EngineClient, DataModels } from '@5minds/processcube_engine_client'; | ||
const engineUri = 'http://localhost:10560'; | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
const client = new EngineClient(engineUri); | ||
const userTasks = await client.userTasks.query({ | ||
processModelId: 'myProcessModelId', | ||
state: DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended, | ||
}); | ||
const userTasks = await client.userTasks.query({ | ||
processModelId: 'myProcessModelId', | ||
state: DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended, | ||
}); | ||
console.log(userTasks); | ||
} | ||
run(); | ||
console.log(userTasks); | ||
``` | ||
## How to use External Task Workers | ||
## External Task Worker | ||
An External Task worker is designed to process External Tasks associated with a BPMN ServiceTask. | ||
External Task Worker werden dazu benutzt, um die an einer Prozessinstanz anfallenden `External Service Tasks` zu verarbeiten. | ||
### Basic | ||
Ein Worker benötigt minimal die folgenden 3 Einstellungen | ||
- Die URL der Ziel-Engine | ||
- Das Topic der abzuarbeitenden External Tasks | ||
- Eine Handler Funktion zum Verarbeiten der External Tasks | ||
You need to provide three arguments to a worker: | ||
Beispiel: | ||
- The url of the Engine where the worker should connect to | ||
- The topic by which to poll External Tasks | ||
- A handler function for processing the External Tasks | ||
```ts | ||
import {EngineClient, DataModels} from '@5minds/processcube_engine_client'; | ||
import {ExternalTaskWorker} from '@5minds/processcube_engine_client'; | ||
@@ -238,10 +176,6 @@ interface AddPayload { | ||
async function run() { | ||
const client = new EngineClient(engineUri); | ||
const externalTaskWorker = new ExternalTaskWorker<AddPayload, AddResult>(url, topic, doAdd, config); | ||
const externalTaskWorker = await client.externalTasks.subscribeToExternalTaskTopic(topic, doAdd); | ||
externalTaskWorker.start(); | ||
externalTaskWorker.start(); | ||
} | ||
async function doAdd( | ||
@@ -251,3 +185,2 @@ payload: AddPayload, | ||
): Promise<AddResult> { | ||
const result: AddResult = { | ||
@@ -257,18 +190,9 @@ sum: payload.number1 + payload.number2, | ||
console.log('Receive payload from process instance'); | ||
console.log(JSON.stringify(payload)); | ||
return Promise.resolve(result); | ||
return result; | ||
} | ||
run(); | ||
``` | ||
Note that by subscribing to a single topic, you create a specific worker for this topic. | ||
Der Worker lässt sich mit folgendem Befehl starten: | ||
### Starting and stopping | ||
Start the worker with: | ||
```ts | ||
@@ -278,3 +202,3 @@ externalTaskWorker.start(); | ||
And stop it with: | ||
und mit folgendem Befehl stoppen: | ||
@@ -285,4 +209,2 @@ ```ts | ||
### Code Samples | ||
You can find [executable code samples here](./samples/external_task_worker) and [here](https://github.com/atlas-engine/ClientSamples/tree/develop/Client.ts). | ||
Ein ausführbares Code-Beispiel [findet sich hier](./samples/external_task_worker/). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
579026
2
206
7
+ Added@5minds/processcube_engine_sdk@3.3.2-hotfix-5e5851-ll1zhz20(transitive)
- Removed@5minds/processcube_engine_sdk@3.3.0(transitive)
Updated@5minds/processcube_engine_sdk@3.3.2-hotfix-5e5851-ll1zhz20