Kue connecting to localhost instead of the AWS elasticache host

644 Views Asked by At

I'm passing these configurations to my queue:

module.exports = {
    host: 'xxxxx-cluster.abnjj1.ng.0001.use1.cache.amazonaws.com',
    port: 6379
}

And creating the kue:

const kue = require('kue')
const MailJob = require('../app/jobs/MailJob.js')
const redisConfig = require('../config/redis')
const jobs = [MailJob]

class Queue {
    constructor(){
        this.kue = kue.createQueue(redisConfig)

        this.processQueue()
    }

    processQueue(){
        return jobs.forEach(job => this.kue.process(job.key, job.handle))
    }
}

module.exports = new Queue()

But it's returning always the same error related to connection with localhost. That's not make sense because i'm passing the host of elasticache

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14)
Emitted 'error' event on Queue instance at:
    at RedisClient.<anonymous> (/home/laurabeatris/Área de trabalho/personal projects/kue-test/node_modules/kue/lib/redis.js:65:13)
    at RedisClient.emit (events.js:209:13)
    at RedisClient.on_error (/home/laurabeatris/Área de trabalho/personal projects/kue-test/node_modules/kue/node_modules/redis/index.js:401:14)
    at Socket.<anonymous> (/home/laurabeatris/Área de trabalho/personal projects/kue-test/node_modules/kue/node_modules/redis/index.js:279:14)
    at Socket.emit (events.js:209:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6379
} 

Am i'm missing something?

1

There are 1 best solutions below

2
Tuan Anh Tran On

Because you're passing options wrong, hence it's pickup the default. check the documentation again, you'll see that redis config goes into redis key of the config

example

var q = kue.createQueue({
  prefix: 'q',
  redis: {
    port: 1234,
    host: '10.0.50.20',
    auth: 'password',
    db: 3, // if provided select a non-default redis db
    options: {
      // see https://github.com/mranney/node_redis#rediscreateclient
    }
  }
});

in your case

this.kue = kue.createQueue({ redis: redisConfig })