0.0.1 • Published 5 months ago

@ht-os/nestjs-protobuf v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

HT OS - NestJS ProtoBuf

安装

pnpm add @ht-os/nestjs-protobuf

使用方法

Producer

services.module.ts

import { ProtobufModule } from '@ht-os/nestjs-protobuf';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    ProtobufModule.forRoot({
      loader: {
        paths: [join(__dirname, '../proto')],
      },
      codec: {
        compress: true,
        compressThreshold: 1024,
      },
    }),
  ],
})
export class ServicesModule {}

Consumer

main.ts

import {
  ProtobufConsumerDeserializer,
  ProtobufConsumerSerializer,
} from '@ht-os/nestjs-protobuf';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

const app = await NestFactory.createMicroservice<MicroserviceOptions>(
  AppModule,
  {
    transport: Transport.NATS,
    options: {
      servers: ['nats://localhost:4222'],
      serializer: app.get(ProtobufConsumerSerializer),
      deserializer: app.get(ProtobufConsumerDeserializer),
    },
  },
);

app.module.ts

import { ProtobufModule } from '@ht-os/nestjs-protobuf';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    ProtobufModule.forRoot({
      isGlobal: true,
      loader: {
        paths: [join(__dirname, '../proto')],
      },
      codec: {
        compress: true,
        compressThreshold: 1024,
      },
    }),
  ],
})
export class AppModule {}
0.0.1

5 months ago