Gtchweb
Gtchweb

Reputation: 69

NestJS, Bull Queue and Redis in production

I have a project using NestJS version 9.2.0 with Bull Queue version 4.9.0 which is connecting to Redis to schedule jobs.

Locally this is working as expected, however, when deploying to staging then Bull won't connect and it fails with error maxRetriesPerRequest.

My assumption is that on staging Bull is not being able to connect over TLS connection, however I am unable to confirm that this is definitely the issue.

I have tried the following without having any success:

  1. set the Redis url as rediss://.....
  2. pass the parameter ?tls=true at the end of the Redis url
  3. pass an empty tls: {} object as part of the Redis configuration which I then use within the BullModule that I am importing as use as factory within the app.module file

The reasons why I suspect it is an issue related to TLS connection:

  1. the local connection works just fine
  2. when I set an invalid URL locally mocking a scenario where Bull cannot connect to Redis I experience the same behaviour in the console as it happens on staging and production
  3. I ensured that the Redis instance on staging and production is up and running and that the url I am using in the app is correct

Upvotes: 3

Views: 1658

Answers (1)

eevee
eevee

Reputation: 1

I had a same issue on production environment, and my problem was a bullModule setting.

My app.module.ts was like:

BullModule.registerQueue(
            {
                name: 'a',
                redis: {
                    host: process.env.REDIS_HOST,
                    port: Number(process.env.REDIS_PORT),
                },
            },
            {
                name: 'b',
                redis: {
                    host: process.env.REDIS_HOST,
                    port: Number(process.env.REDIS_PORT),
                },
            },
        ),

I fixed it like:

 BullModule.forRoot({
            redis: {
                host: process.env.REDIS_HOST,
                port: Number(process.env.REDIS_PORT),
            },
        }),
        BullModule.registerQueue(
            {
                name: 'a',
            },
            {
                name: 'b',
            },
        ),

After I fixed my code this way, it works just fine. (You can also follow the nest.js document.)

Upvotes: 0

Related Questions