npm.io
1.0.1 • Published 4 years ago

@dap-js/nest-adapter

Licence
MIT
Version
1.0.1
Deps
2
Size
12 kB
Vulns
0
Weekly
0

@dap-js/nest-adapter

NestJS microservice adapter for DAP application protocol

Usage

Server

// Controller

@Controller()
class AppController {
  @MessagePattern(42)
  testHandler(req: unknown) {
    controllerSpy(req);
    return Buffer.from('General Kenobi?');
  }
}

// main.ts

import { NestFactory } from "@nestjs/core";
import { DapMicroserviceServer } from "@dap-js/nest-adapter";

const app = NestFactory.createMicroservice(AppModule, {
    strategy: new DapMicroserviceServer({port: 1313}),
});

microservice = await app;
await microservice.listen();
Client
import { DapMicroserviceClient } from '@dap-js/nest-adapter';
import { firstValueFrom } from 'rxjs';

const client = new DapMicroserviceClient('dap://localhost:1313');
const result = await firstValueFrom(client.send<number, {token?: Buffer, payload?: Buffer}>(42, { payload: Buffer.from('Hello there!')}));