0.4.6 • Published 2 years ago
google-cloud-pubsub-with-nestjs-custom-transporters v0.4.6
Google Cloud Pub Sub with NestJS
Google Cloud Pub Sub을 NestJS Custom transporters를 이용해서 사용해보자.
Example
Server
//main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { MicroserviceOptions } from '@nestjs/microservices';
import { CloudPubSubServer } from 'google-cloud-pubsub-with-nestjs-custom-transporters';
async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
strategy: new CloudPubSubServer({
projectId: 'your-project-id',
subscriptionName: 'your-subscription-name',
}),
});
await app.listen();
}
bootstrap();
// app.controller.ts
import { Controller } from '@nestjs/common';
import { MessagePattern, Payload } from '@nestjs/microservices';
@Controller()
export class AppController {
@MessagePattern('your-pattern')
subscribeMessage(@Payload() payload) {
console.log('your-pattern', payload);
}
}
Client
// app.module.ts
import { Module } from '@nestjs/common';
import { AppService } from './app.service';
import { CloudPubSubClientModule } from 'google-cloud-pubsub-with-nestjs-custom-transporters';
@Module({
imports: [
CloudPubSubClientModule.register({
projectId: 'your-project-id',
topicName: 'your-topic-name',
}),
],
providers: [AppService],
})
export class AppModule {}
import { Inject, Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { PUBSUB_CLIENT } from 'google-cloud-pubsub-with-nestjs-custom-transporters';
@Injectable()
export class AppService {
constructor(@Inject(PUBSUB_CLIENT) private readonly pubsubClient: ClientProxy) {}
async publish() {
this.pubsubClient.send('your-pattern', 'hello').subscribe(console.log);
}
async dispatch() {
this.pubsubClient.emit('your-pattern', 'hello');
}
}
Reference
0.4.6
2 years ago
0.4.5
2 years ago
0.4.4
2 years ago
0.4.3
2 years ago
0.4.2
2 years ago
0.4.1
2 years ago
0.4.0
2 years ago
0.3.9
2 years ago
0.3.8
2 years ago
0.3.7
2 years ago
0.3.6
2 years ago
0.3.5
2 years ago
0.3.4
2 years ago
0.3.3
2 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.0
2 years ago
0.2.9
2 years ago
0.2.8
2 years ago
0.2.7
2 years ago
0.2.6
2 years ago
0.2.4
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.9
2 years ago
0.1.8
2 years ago
0.1.7
2 years ago
0.1.6
2 years ago
0.1.5
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago