@payk/nestjs-zeebe
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

Nest Logo

NestJS Zeebe Connector (Transport and Client)

A zeebe transport and client for NestJS

Using the zeebe-node module and exposing it as a NestJS transport and module.

Build Status

Install

npm install @payk/nestjs-zeebe

Basic usage

    // app.module.ts
    import { Module } from '@nestjs/common';
    import { AppController } from './app.controller';
    import { ZeebeModule, ZeebeServer } from '@payk/nestjs-zeebe';

    @Module({
    imports: [ ZeebeModule.forRoot({ gatewayAddress: 'localhost:26500' })],
    controllers: [AppController],
    providers: [ZeebeServer],
    })
    export class AppModule {}
    // main.ts
    import { NestFactory } from '@nestjs/core';
    import { AppModule } from './app.module';
    import { ZeebeServer } from '@payk/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();
    // 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 '@payk/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<CreateWorkflowInstanceResponse> {
            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<any> {
            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<any>) {
            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);
        }
    }

Dependencies (0)

    Dev Dependencies (18)

    Package Sidebar

    Install

    npm i @payk/nestjs-zeebe

    Weekly Downloads

    9

    Version

    1.2.2

    License

    ISC

    Unpacked Size

    29.7 kB

    Total Files

    33

    Last publish

    Collaborators

    • dankopayk
    • danpayk
    • one_eye_jackei
    • oromano