weyoss / redis-smq

A simple high-performance Redis message queue for Node.js.
MIT License
596 stars 64 forks source link

Config is ignored #105

Closed realchandan closed 1 year ago

realchandan commented 1 year ago

I am having the same issue as 88.

import {
  Consumer,
  Message,
  Producer,
  QueueManager,
  Message as SMQMessage
} from "redis-smq";
import {
  ICallback,
  RedisClientName
} from "redis-smq-common/dist/types/index.js";
import { EQueueType } from "redis-smq/dist/types/index.js";

(async () => {
  QueueManager.createInstance(
    {
      namespace: "ns1",
      redis: {
        client: RedisClientName.REDIS_V4,
        options: {
          connectTimeout: 3600000,
          host: "18.130.130.108",
          port: 6379
        }
      },
      logger: {
        enabled: true,
        options: {
          level: "info"
        }
      }
    },
    (err, queueManager) => {
      if (!err) {
        console.log("success");
        return;
      }
      console.log(err);
    }
  );
})();

Even though I'm specifying a custom host and port, It throws Error: connect ECONNREFUSED 127.0.0.1:6379

weyoss commented 1 year ago

@realchandan Thank you for opening this issue.

That is totally normal as you are providing wrong Redis client options. RedisClientName.REDIS_V4 does not support such options as connectTimeout, host, and port so they are simply ignored.

You should try it this way:

QueueManager.createInstance(
    {
      namespace: "ns1",
      redis: {
        client: RedisClientName.REDIS_V4,
        options: {
            socket: {
                connectTimeout: 3600000,
                host: "18.130.130.108",
                port: 6379
            }
        }
      },
      logger: {
        enabled: true,
        options: {
          level: "info"
        }
      }
    },
    (err, queueManager) => {
      if (!err) {
        console.log("success");
        return;
      }
      console.log(err);
    }
  );

See https://github.com/redis/node-redis/blob/master/docs/client-configuration.md for more details about valid options for RedisClientName.REDIS_V4

realchandan commented 1 year ago

Thank You, my issue is now resolved, I'm sorry that I didn't read the docs properly!