1.1.10 • Published 1 year ago

@gojob/nest-cloud-pub-sub-transport v1.1.10

Weekly downloads
67
License
MIT
Repository
github
Last release
1 year ago

Nest Cloud Pub/Sub Transport

CircleCI

A Custom Transport strategy for Cloud Pub/Sub in Nest microservices.

TODO: in order to open-source it for NestJs, we must use loadPackage (from Server) to load @google-cloud/pubsub dynamically instead of having it installed in the dependenices of the project. Also, all types used from this package should be duplicated into local types/interfaces.

Getting started

yarn add @gojob/nest-cloud-pub-sub-transport
# or
npm install @gojob/nest-cloud-pub-sub-transport

Here is an example of implementation in your Nest application:

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const configService = app.get(ConfigService);

  app.connectMicroservice({
    strategy: new CloudServerPubSub({
      // "clientConfig": configuration passed "as is" to the Cloud PubSub client
      clientConfig: {
        keyFile: configService.get('GCP_KEY_FILE_PUBSUB'),
      },
      // "options": custom options, specific to this package
      options: {
        logger: app.get(LOGGER),
        // useful when your app is using a single topic & subscription
        defaultTopic: configService.get('DEFAULT_PUB_SUB_TOPIC'),
        defaultSubscription: configService.get('DEFAULT_PUB_SUB_SUBSCRIPTION'),
      },
    }),
  });

  await app.startAllMicroservices();
  await app.listen(3000);
}

Then use @EventPattern from @nestjs/microservices to decorate the event handlers which will be called when a new Pub/Sub message is received in your target topic(s).

Contributing

CommandAction
yarn compileEnsure the TypeScript code can be compiled using tsc
yarn buildBuild the project (transpile the code to JavaScript)
yarn lintLint the code (ESLint)
yarn testRun unit tests
yarn integrationRun integration tests
1.1.10

1 year ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.9-beta.0

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago