question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RabbitMQ: events are being consumed before application is ready on Nest 8

See original GitHub issue

Hey all, I’m running into an issue where RabbitMQ consumers start up and consume events before the main Nest application is completely initialized. This started happening after we migrated from Nest 7 to Nest 8. I’ve resolved the issue in my application by moving the RabbitMQ module to the very end of the application module imports list:

// consumers start before application initialized
@Module({
  imports: [
    RabbitMQModule,
    ...ModulesThatDependOnRabbitMQ
  ]
})

// consumers start after application initialized 
@Module({
  imports: [
    ...ModulesThatDependOnRabbitMQ,
    RabbitMQModule
  ]
})

Package versions:

@nestjs/core@8.2.6
@nestjs/common@8.2.6
@golevelup/nestjs-rabbitmq@1.18.1

Is anybody else seeing this behaviour?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
WonderPandacommented, Jan 27, 2022

I think it should probably be fine for us to move all the logic from onModuleInit to onApplicationBootstrap like you suggested.

@ckfngod I don’t think the order of the imports actually matters in your case, its more likely that its just a lucky thing with the timing that you happen to see a difference when you reorder the array

1reaction
ckfngodcommented, Jan 29, 2022

@underfisk @WonderPanda Thanks for the responses. Yeah it looks like it’s definitely lucky timing, wasn’t able to get it to work in my sample app. I’m seeing issues specifically with this in combination with a GRPC microservice. Rabbit consumers will begin processing events before the GRPC service is ready so as the application starts up it will throw a bunch of errors but afterwards it works fine.

Sample app is here: https://github.com/ckfngod/rabbitmq-app-init-issue

Start up the app to assert the queue, stop the app, publish a couple events to the queue then start the app again and you should see the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consumer Acknowledgements and Publisher Confirms
When a consumer (subscription) is registered, messages will be delivered (pushed) by RabbitMQ using the basic.deliver method. The method carries a delivery ...
Read more >
RabbitMQ - Microservices - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines ...
Read more >
RabbitMQ constant memory increase (binary_alloc) in idle state
I have detected a strange behavior on all of our RabbitMQ instances in different environments, where memory usage seem to increase with ~...
Read more >
Handling of rabbit messages via NESTJs microservice issue
I'm running an NestJS microservice against a RabbitMQ broker to get messages that arrive from IOT devices and insert them into a MySQL...
Read more >
Nest.js has trouble connecting to RabbitMQ with latest amqp ...
rabbitmq.reply-to' before setting up a consumer listening on that queue (as per this). This sounds like a bug outside of amqp-connection ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found