zeebe-node-nestjs
v1.0.0
Published
Zeebe-Node client wrapper for NestJS
Downloads
5
Maintainers
Readme
Sample
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ZeebeServer } from 'zeebe-node-nestjs';
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.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { ZeebeModule, ZeebeServer } from 'zeebe-node-nestjs';
@Module({
imports: [
ZeebeModule.forRoot({ gatewayAddress: 'localhost:26500' })
],
controllers: [AppController],
providers: [ZeebeServer],
})
export class AppModule {}
// app.controller.ts
import { Controller, Get, Inject } from '@nestjs/common';
import { AppService } from './app.service';
import { ZBClient, Duration } from 'zeebe-node';
import { ZEEBE_CONNECTION_PROVIDER, ZeebeWorker } from 'zeebe-node-nestjs';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
@Inject(ZEEBE_CONNECTION_PROVIDER)
private readonly zbClient: ZBClient,
) {}
// Use the client to create a new process instance
@Get()
getHello(): Promise<CreateWorkflowInstanceResponse> {
return this.zbClient.createProcessInstance('Process_sample', { test: 1 });
}
// Subscribe to events of type 'Activity_test'
@ZeebeWorker('Activity_test')
async test(job) {
console.log(job);
this.appService.doSomething();
job.complete();
}
// publish a message
@Post()
sendHello() {
this.zbClient.publishMessage({
name: 'message_notification',
correlationKey: '1234',
variables: { greeting: 'Hello' },
timeToLive: Duration.seconds.of(10),
});
}
}