https://github.com/camunda-community-hub/nestjs-zeebe
Zeebe transport and client for nestjs framework
https://github.com/camunda-community-hub/nestjs-zeebe
Last synced: 4 months ago
JSON representation
Zeebe transport and client for nestjs framework
- Host: GitHub
- URL: https://github.com/camunda-community-hub/nestjs-zeebe
- Owner: camunda-community-hub
- License: mit
- Fork: true (pay-k/nestjs-zeebe)
- Created: 2020-09-01T11:11:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T16:17:36.000Z (over 1 year ago)
- Last Synced: 2024-05-16T10:37:57.373Z (12 months ago)
- Language: TypeScript
- Size: 260 KB
- Stars: 24
- Watchers: 4
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-camunda-platform-8 - NestJS
README
[](https://github.com/camunda-community-hub/community) [](https://github.com/Camunda-Community-Hub/community/blob/main/extension-lifecycle.md#stable-) 
# NestJS Zeebe Connector (Transport and Client) - Up-to-date
A zeebe transport and client for NestJS 7.xUsing the zeebe-node module and exposing it as a NestJS transport and module.
[](https://dansh.visualstudio.com/nestjs-zeebe/_build/latest?definitionId=2&branchName=master)# Use version 2.x.x and above for Zeebe 1.x.x and above
## Install
npm install nestjs-zeebe## Basic usage
```ts
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { ZeebeModule, ZeebeServer } from 'nestjs-zeebe';@Module({
imports: [ ZeebeModule.forRoot({ gatewayAddress: 'localhost:26500' })],
controllers: [AppController],
providers: [ZeebeServer],
})
export class AppModule {}
``````ts
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ZeebeServer } from 'nestjs-zeebe';async function bootstrap() {
const app = await NestFactory.create(AppModule);
const microservice = app.connectMicroservice({
strategy: app.get(ZeebeServer),
});await app.startAllMicroservicesAsync();
await app.listen(3000);
}
bootstrap();```
```ts
// app.controller.ts
import { Controller, Get, Inject } from '@nestjs/common';
import { AppService } from './app.service';
import { ZBClient } from 'zeebe-node';
import { ZEEBE_CONNECTION_PROVIDER, ZeebeWorker, ZeebeJob } from 'nestjs-zeebe';
import {
Ctx,
Payload,
} from '@nestjs/microservices';
import { ZBClient, ZBWorker, ICustomHeaders, IInputVariables, IOutputVariables, CompleteFn } from 'zeebe-node';
import { CreateProcessInstanceResponse } from 'zeebe-node/dist/lib/interfaces-grpc-1.0';@Controller()
export class AppController {
constructor(private readonly appService: AppService, @Inject(ZEEBE_CONNECTION_PROVIDER) private readonly zbClient: ZBClient) {}// Use the client to create a new workflow instance
@Get()
getHello() : Promise {
return this.zbClient.createProcessInstance('order-process', { test: 1, or: 'romano'});
}// Subscribe to events of type 'payment-service
@ZeebeWorker('payment-service')
paymentService(@Payload() job: ZeebeJob, @Ctx() context: { complete: CompleteFn, worker: ZBWorker }) {
console.log('Payment-service, Task variables', job.variables);
let updatedVariables = Object.assign({}, job.variables, {
paymentService: 'Did my job',
});// Task worker business logic goes here
job.complete(updatedVariables);
}// Subscribe to events of type 'inventory-service and create a worker with the options as passed below (zeebe-node ZBWorkerOptions)
@ZeebeWorker('inventory-service', { maxJobsToActivate: 10, timeout: 300 })
inventoryService(@Payload() job: ZeebeJob, @Ctx() context: { complete: CompleteFn, worker: ZBWorker }) {
console.log('inventory-service, Task variables', job.variables);
let updatedVariables = Object.assign({}, job.variables, {
inventoryVar: 'Inventory donnnneee',
});// Task worker business logic goes here
//job.complete(updatedVariables);
job.complete(updatedVariables);
}
}```
## For v1.x.x
```ts
// app.controller.ts
import { Controller, Get, Inject } from '@nestjs/common';
import { AppService } from './app.service';
import { ZBClient } from 'zeebe-node';
import { CreateWorkflowInstanceResponse, CompleteFn, Job } from 'zeebe-node/interfaces';
import { ZEEBE_CONNECTION_PROVIDER, ZeebeWorker } from 'nestjs-zeebe';
import {
Ctx,
Payload,
} from '@nestjs/microservices';@Controller()
export class AppController {
constructor(private readonly appService: AppService, @Inject(ZEEBE_CONNECTION_PROVIDER) private readonly zbClient: ZBClient) {}// Use the client to create a new workflow instance
@Get()
getHello() : Promise {
return this.zbClient.createWorkflowInstance('order-process', { test: 1, or: 'romano'});
}// Subscribe to events of type 'payment-service
@ZeebeWorker('payment-service')
paymentService(@Payload() job, @Ctx() fn: CompleteFn {
console.log('Payment-service, Task variables', job.variables);
let updatedVariables = Object.assign({}, job.variables, {
paymentService: 'Did my job',
});// Task worker business logic goes here
complete.success(updatedVariables);
}// Subscribe to events of type 'inventory-service and create a worker with the options as passed below (zeebe-node ZBWorkerOptions)
@ZeebeWorker('inventory-service', { maxJobsToActivate: 10, timeout: 300 })
inventoryService(@Payload() job, @Ctx() fn: CompleteFn) {
console.log('inventory-service, Task variables', job.variables);
let updatedVariables = Object.assign({}, job.variables, {
inventoryVar: 'Inventory donnnneee',
});// Task worker business logic goes here
complete.success(updatedVariables);
}
}```
###### Hint:
For mac, you need to have xcode installed
```xcode-select --install```