1.10.0 • Published 2 years ago
nestjs-pubsub-transport v1.10.0
nestjs-pubsub-transport
Custom transport for Google PubSub for NestJS framework
Installation:
npm i nestjs-pubsub-transport
Examples
install module
@Module({
imports: [
PubsubTransportModule.forRootAsync({
inject: [],
useFactory: () => ({
topic: 'topic-name',
subscription: 'subscription-name',
ackDeadline: 10, // optional
maxMessages: 10, // optional
getPattern: (msg: Message) => msg.attributes.yourPattern, // optional
deserializeMessage: (msg: Message) => msg.data,
}),
}),
SomeModule,
],
})
export class AppModule {
}
@Module({
imports: [
PubsubTransportModule.forRoot({
topic: 'topic-name',
subscription: 'subscription-name',
ackDeadline: 10, // optional
maxMessages: 10, // optional
getPattern: (msg: Message) => msg.attributes.yourPattern, // optional
deserializeMessage: (msg: Message) => msg.data,
}),
SomeModule,
],
})
export class AppModule {
}
Controller example
import { Controller } from '@nestjs/common';
import { MessagePattern, Payload } from '@nestjs/microservices';
import { PubSubInterceptor } from 'nestjs-pubsub-transport';
// Use interceptor, to correctly catch errors, otherwise transport will always 'ack' message
@UseInterceptors(PubSubInterceptor)
@Controller()
export class ClientsController {
constructor() {
}
// Make sure that your methods in controllers does not return anything, it might break
// error handling logic
@MessagePattern('pattern')
authorize(@Payload() data: AuthorizeClientMessage) {
console.log('handle message', data);
}
}
Connect transport as microservice
// connect pubsub transport
app.connectMicroservice({
strategy: app.get(PubSubTransport),
});
Start transport
await app.startAllMicroservicesAsync();
Bootstrapped with: create-ts-lib-gh
This project is Mit Licensed.
1.10.0
2 years ago
1.9.1
2 years ago
1.9.0
2 years ago
1.8.0
2 years ago
1.9.2
2 years ago
1.7.2
2 years ago
1.7.1
2 years ago
1.7.0
2 years ago
1.6.0
2 years ago
1.5.0
3 years ago
1.4.2
3 years ago
1.4.1
3 years ago
1.4.0
3 years ago
1.3.2
3 years ago
1.3.1
3 years ago
1.3.0
3 years ago
1.2.2
3 years ago
1.2.1
3 years ago
1.2.0
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.0
3 years ago