0.2.0 • Published 4 years ago

@ayerin/nest-seneca-transport v0.2.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
4 years ago

@rentspree/nest-seneca-transport

Table of Contents

About

Write about 1-2 paragraphs describing the purpose of your project.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

This library is hosted on Gemfury as a private repository.

To install, you must grant RentSpree gemfury an access to your npm.

First, you need to config npm to use gemfury proxy for @rentspree package namespace.

npm config set @rentspree:registry https://npm-proxy.fury.io/rentspree/

Then, login your gemfury account.

npm login --registry https://npm-proxy.fury.io/rentspree/

You'll be prompted to input your credentials.

Installing

Just run npm install command.

npm i @rentspree/nest-seneca-transport

Usage

Initialize ServerSeneca into the Microservice strategy

async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    strategy: new ServerSeneca({
      serializer: new OutboundResponseIdentitySerializer(),
      deserializer: new InboundResponseIdentityDeserializer(),
      senecaInstance: new Seneca(),
    })
  app.listen(() => console.log('Microservice is listening'));
}
bootstrap();

Then, use MessagePattern decorator on any controller you want.

@MessagePattern({
  role: 'Property',
  version: '2.1',
  cmd: 'getByRenter',
})      // Annotation for Seneca transport layer
@Get()  // Annotation for running normal REST-API
getByRenter(data: any): Promise<[Property]> {
  const { renter } = data;
  const properties = await this.propertyService.getByRenter(renter)
  return properties;
}
0.2.0

4 years ago