0.4.6 • Published 3 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
3 years ago
0.4.5
3 years ago
0.4.4
3 years ago
0.4.3
3 years ago
0.4.2
3 years ago
0.4.1
3 years ago
0.4.0
3 years ago
0.3.9
3 years ago
0.3.8
3 years ago
0.3.7
3 years ago
0.3.6
3 years ago
0.3.5
3 years ago
0.3.4
3 years ago
0.3.3
3 years ago
0.3.2
3 years ago
0.3.1
3 years ago
0.3.0
3 years ago
0.2.9
3 years ago
0.2.8
3 years ago
0.2.7
3 years ago
0.2.6
3 years ago
0.2.4
3 years ago
0.2.3
3 years ago
0.2.2
3 years ago
0.2.1
3 years ago
0.2.0
3 years ago
0.1.9
3 years ago
0.1.8
3 years ago
0.1.7
3 years ago
0.1.6
3 years ago
0.1.5
3 years ago
0.1.4
3 years ago
0.1.3
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.7
3 years ago
0.0.6
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago