Code Monkey home page Code Monkey logo

nestjs-zeebe's Introduction

Sponsored by Precise Finance
Sponsored by Precise

Community extension badge Lifecycle: Stable badge Compatible with: Camunda Platform 8

Nest Logo

NestJS Zeebe Connector (Transport and Client) - Up-to-date

A zeebe transport and client for NestJS 7.x

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

Build Status

Use version 2.x.x and above for Zeebe 1.x.x and above

Install

npm install nestjs-zeebe

Basic usage

    // 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 {}
    // 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();
    // 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<CreateProcessInstanceResponse> {
            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<IOutputVariables>, worker: ZBWorker<IInputVariables, ICustomHeaders, IOutputVariables> }) {
            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<IOutputVariables>, worker: ZBWorker<IInputVariables, ICustomHeaders, IOutputVariables> }) {
            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

    // 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<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);
        }
    }



Hint:

For mac, you need to have xcode installed xcode-select --install

Sponsored by Precise Finance
Sponsored by Precise

nestjs-zeebe's People

Contributors

celanthe avatar dankoprecise avatar danshapir avatar jwulf avatar wisekaa03 avatar xomiamoore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nestjs-zeebe's Issues

SAXException while parsing input stream

Hi,
I was trying to deploy a Zeebe process with nestjs-zeebe 2.0.0, like so:
@Inject(ZEEBE_CONNECTION_PROVIDER) private readonly zbClient: ZBClient
const deployed = await this.zbClient.deployProcess('test2.bpmn')
However, I get the following error:

Error: 3 INVALID_ARGUMENT: Command 'CREATE' rejected with code 'INVALID_ARGUMENT': Expected to deploy new resources, but encountered the following errors:
'test2.bpmn': SAXException while parsing input stream

I checked the logs on my Zeebe container and found that it was "Caused by: org.xml.sax.SAXException: Fatal Error: URI=null Line=1: Premature end of file."
I checked my bpmn file and it seems fine.
If I use instead zeebe-node 1.3.4 directly, the process is deployed successfully:

import { ZBClient } from 'zeebe-node'
const zbc = new ZBClient('zeebe:26500')
const deployed = await zbc.deployProcess('test2.bpmn')

Any idea of what can it be? Thank you in advance 🙂

Support Zeebe 1.0.0

Zeebe 1.0.0 is coming down the pipeline. It is roughly expected in April. It contains breaking changes to the client API. I'm expecting to see these changes merged in alpha2 in March.

I've created a branch of zeebe-node for 1.0.0 that deprecates the v0 API methods on the zeebe-node API surface and redirects them to the new v1 API methods. It should be a drop-in replacement with no need to change the NestJS integration code (and you can change it to use the new v1 API methods, and should at some point).

Applications using the v1 package cannot communicate with v0 brokers. The v1 package is backward compatible with v0 application code, but not v0 brokers.

More details here: https://forum.zeebe.io/t/changelog-for-zeebe-client-lib-maintainers/2064

Grpc Stream Error: 13

3 zeebe brokers and 2 zeebe gateways have been installed on a k8s platform. To enable external access to the gateway from outside k8s, an ALB ingress has been used.

When connecting to the publicly exposed endpoint getting this error ERROR: Grpc Stream Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: Protocol error

But using zbctl i am able to connect and get the status from that endpoint. Please let me know if anything needs to be changes

worker can not subscribe camunda8 service

I use @ZeebeWorker subscribe zeebe event, but can not called when I create a ProcessInstance。
but I use pure zeebe-node,all is OK.

nestjs-zeebe code:
@ZeebeWorker('demo-service')
demoService(@payload() job: ZeebeJob, @ctx() context: any) {
console.log('context is: ', context);
console.log('demo-service task variables: ', job.variables);
job.complete();
}

and zeebe-node code(i use postman call this function):
@get('createWorker')
getTaskList() {
this.zbClient.createWorker({
taskType: 'demo-service',
taskHandler: taskHandler,

  onReady: () => console.log('worker connected'),
  onConnectionError: () => console.log('Worker disconnected'),
});

return 'tasklist';

}
}

function taskHandler(job: ZeebeJob) {
console.log('job', job.variables);
return job.complete();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.