golevelup / nestjs

A collection of badass modules and utilities to help you level up your NestJS applications 🚀
MIT License
2.26k stars 259 forks source link

RabbitMQ - returning `consumerTag` when creating subscribers #755

Closed gunesyu closed 1 month ago

gunesyu commented 2 months ago

There seems to be a promise resolve issue about createSubscriber method that prevents consumerTag to return in success callback.

Is there any other way to retrieve the consumerTag to use for cancelling/resuming specific consumers?

  public async createSubscriber<T>(
    handler: SubscriberHandler<T>,
    msgOptions: MessageHandlerOptions,
    originalHandlerName: string,
    consumeOptions?: ConsumeOptions
  ): Promise<SubscriptionResult> {
    return new Promise((res) => {
      let result: SubscriptionResult;
      this.selectManagedChannel(msgOptions?.queueOptions?.channel)
        .addSetup(async (channel) => {
          const consumerTag = await this.setupSubscriberChannel<T>(
            handler,
            msgOptions,
            channel,
            originalHandlerName,
            consumeOptions
          );
          result = { consumerTag };
        })
        .then(() => {
          res(result);
        });
    });
  }

PS. I'd like to contribute by opening a pr that fixes this issue if the intended behavior is as expected.