How can I use nejst js bull queue with redis cluser in kubernetes

51 Views Asked by At

I'm working on an application with Nest.js where I've been using Nest.JS bull Queue for task scheduling. The problem is that it's working as expected in locally, but not working on the server.

It's unable to add the task to the queue. In the server as of I knwo redis is deployed in kubernetes cluster, that is it has multiple instaces and I only have the service url. How can I resolve this issue?

The redis url is : redis://redis-cluster.redis.svc

I tried this way

App.module.ts @Module({ imports: [ RedisModule, BullModule.forRoot({ redis: { host: process.env.REDIS_ENDPOINT, port: 6379, } })

in service.module.ts

 BullModule.registerQueue({
       name: "customer-queue",
     }),

In service:

 async addToCustomerQ() {
    this.logger.debug("Task is going to be added");
    await this.customerQueue.add(
      'test',
      { text: "Redis connection established" },
    );

    this.logger.debug("Task added successfully");
  }

In processor:

@Processor("customer-queue")
export class IntegrationProcessor {
    private readonly logger = new Logger(IntegrationProcessor.name);


    @Process('test')
    async checkRedisTask(job: Job) {
        console.log({ job: job.data })

        this.logger.debug("(Processor)Test task added with id: " + job.id);
        this.logger.warn(job?.data?.text);
    }
}
0

There are 0 best solutions below