Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopping consumers #66

Open
joelclouddistrict opened this issue Oct 2, 2023 · 3 comments
Open

Stopping consumers #66

joelclouddistrict opened this issue Oct 2, 2023 · 3 comments

Comments

@joelclouddistrict
Copy link

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
Copy link

ruscon commented Dec 14, 2023

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

@schm-dt
Copy link

schm-dt commented Jan 12, 2024

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.

@hugoblanc
Copy link

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

It could be good to add it to the readme. https://github.com/ssut/nestjs-sqs/blob/master/lib/sqs.service.ts#L89-L93 graceful shutdown is already handled by the lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants