ssut / nestjs-sqs

A project to make SQS easier to use within NestJS, with decorator-based handling and seamless NestJS-way integration.
MIT License
200 stars 53 forks source link

Stopping consumers #66

Open joelclouddistrict opened 11 months ago

joelclouddistrict commented 11 months ago

Hello,

I'm trying to figure out how to stop consumers manually. I want to handle the onApplicationShutdown NestJS lifecycle hook and, when it is called, stop the SQS consumer and check that there are no jobs running.

This is the SqsModuleOptionsFactory

@Injectable()
export default class SqsOptionsFactory implements SqsModuleOptionsFactory {
 createOptions(): SqsOptions | Promise<SqsOptions> {
    const consumers = []

    consumers.push({
      name: "the-queue-name",
      queueUrl: "the-queue-url",
      region: "the-queue-region",
    })

    return { consumers, producers: [] }
  }
}

Looking at bbc/sqs-consumer I can see the consumer.stop method, how can I retrieve the consumer to call the stop method?

ruscon commented 9 months ago

https://github.com/ssut/nestjs-sqs/blob/master/lib/sqs.service.ts#L82-L86

schm-dt commented 8 months ago

I was just looking for this when considering how to stop my queue when hitting rate limits from third parties that it uses to process jobs, with the idea that I can keep track of usage and stop the consumer when I know I am approaching or will exceed rate limits. If anyone knows alternative solution to my problem would be interested in ideas.