A Qstash client for NestJS
yarn add nestjs-upstash-qstash
npm i nestjs-upstash-qstash
Entry module:
@Module({
imports: [
QstashModule.register({
token: "<QSTASH_TOKEN>";
})
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Entry module:
@Module({
imports: [
QstashModule.registerAsync({
imports: [ConfigModule.forFeature(config)],
inject: [ConfigService],
async useFactory(config: ConfigService) {
const { token } = config.get<QstashClientConfig>('qstash');
return {
token
};
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Inject qstash client into a service:
@Injectable()
export class AppService {
constructor(@InjectQstash() private readonly qStash: QstashClient) {}
sayHello() {
return this.qStash.publishJSON({
url: 'https://api.awesomeapp.com/v1/greets',
body: {
name: 'John Doe',
message: 'Lorem ipsum',
}
});
}
}
In the controller...
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
public sayHello() {
return this.appService.sayHello();
}
}