Run your business logic anywhere
npm i nestjs-cambpm
The full example can be found here. Please also see the Azure Function Example.
// src/main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.connectMicroservice({
strategy: app.get(ExternalTaskConnector),
});
await app.startAllMicroservicesAsync();
}
bootstrap();
// src/app.module.ts
@Module({
controllers: [AppController],
providers: [
ExternalTaskConnector,
ExternalTaskModule.createClient({
baseUrl: 'http://localhost:8080/engine-rest',
}),
],
})
export class AppModule {}
// src/app.controller.ts
@Controller()
export class AppController {
@Subscription('my-external-task', {
lockDuration: 500,
})
async myExternalTask(@Payload() task: Task, @Ctx() taskService: TaskService) {
const businessKey = task.businessKey;
const isBusinessKeyMissing = !businessKey;
const processVariables = new Variables();
processVariables.set('isBusinessKeyMissing', isBusinessKeyMissing);
if (!isBusinessKeyMissing) {
// Complete the External Task
await taskService.complete(task, processVariables);
Logger.log('External task successfully completed!');
} else {
const errorMessage = 'No business key given!';
const options: HandleFailureOptions = {
errorMessage: errorMessage,
};
// Raise an incident
await taskService.handleFailure(task, options);
Logger.error(errorMessage);
}
}
}