NestJS Qstash Module

Description

A Qstash client for NestJS

Installation

yarn add nestjs-upstash-qstash
npm i nestjs-upstash-qstash


Configuration


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 {}


Usage


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();
  }
}



github twitter linkedin youtube stackoverflow codepen