Skip to content

connectionInitOptions.wait: false still causes application to crash if RabbitMQ is unavailable #1001

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

Open
cidisaac opened this issue Apr 15, 2025 · 1 comment
Labels
enhancement New feature or request rabbitmq

Comments

@cidisaac
Copy link

cidisaac commented Apr 15, 2025

Hi! 👋

I'm currently using @golevelup/nestjs-rabbitmq version 5.7.0 and ran into an issue where the application crashes on startup if RabbitMQ is unavailable, even when connectionInitOptions.wait is set to false.

Here’s a simplified version of the module configuration:

RabbitMQModule.forRootAsync({
  useFactory: async () => ({
    uri: 'amqp://localhost:5672',
    enableControllerDiscovery: true,
    connectionInitOptions: {
      wait: false,
    },
    exchanges: [
      {
        name: 'my-exchange',
        type: 'topic',
        createExchangeIfNotExists: true,
        options: { durable: true },
      },
    ],
  }),
})

My understanding from the docs and the underlying amqp-connection-manager is that wait: false should allow the application to boot even if RabbitMQ is not reachable at startup. However, in practice, the app still throws an exception and fails to start when RabbitMQ is down.

It seems like the issue is related to createExchangeIfNotExists: true, since the library tries to assert the exchange on startup regardless of the connection status. This makes wait: false ineffective in real-world scenarios where availability might be intermittent and resilience is important.

Is this the intended behavior? Is there a workaround or planned improvement to make this option truly non-blocking?

Thanks in advance and great work on the library 🙌

@underfisk
Copy link
Contributor

I think what you're describing totally makes sense and we may be asserting exchanges/throwing if the client is not available, which would be the case when the connection is not established.

It would make sense to create the exchange once the connection is available but the reality is that it is more complicated than that as we need to setup a bunch of stuff around the channels.

I'm open to alternative suggestions such as creating the exchange once the connection is available instead of trying to do that immediately when wait is set to false.

@underfisk underfisk added enhancement New feature or request rabbitmq labels Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rabbitmq
Projects
None yet
Development

No branches or pull requests

2 participants