weyoss / redis-smq

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

Not working with docker compose #90

Closed yantrab closed 2 years ago

yantrab commented 2 years ago

This is my docker-compose file:

version: "3"
services:
  redis-server:
    image: 'redis'
  api:
    build: ./api
    ports:
      - "8080:8080"

And this is my config:

{
  redis: {
    client: RedisClientName.REDIS,
    options: {
      host: 'redis-server'
    },
  },
}

The instance is created without error, but when i execute producer.produce, I get error - [ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379

weyoss commented 2 years ago

This issue is related to docker and is out of scope of this project.

If you feel like there is an issue with redis-smq itself then provide a code example to reproduce the issue.

Related to https://github.com/weyoss/redis-smq/issues/88.

yantrab commented 2 years ago

@weyoss https://github.com/yantrab/-redis-smq-issue

Just run docker-compose up.

I test it with a simple get/set from Redis and it works.

weyoss commented 2 years ago

You forgot to provide the configuration when creating the producer instance:

https://github.com/yantrab/-redis-smq-issue/blob/d2c0b18f20363cd13eeaa204f8c4b9afd8f585d0/app.ts#L22

weyoss commented 2 years ago

Closing as resolved.

OlleMattsson commented 2 years ago

I struggled with this a little bit. So just In case anyone else has a similar issue, I'll leave this here for posterity. The main take away in my case was that redis v4 takes a url or socket.host param in the config: https://github.com/redis/node-redis/blob/master/docs/client-configuration.md

package.json

"redis": "^4.3.0",

docker-compose.yml

version: '2'
services:

  redis:
    image: redis
    container_name: redis
    expose:
      - 6379

  producer:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: producer
    links:
      - redis

producer.js

import {RedisClientName} from "redis-smq-common/dist/types";

const config = {
    redis: {
        client: RedisClientName.REDIS_V4,
        options: {
            url: 'redis://redis:6379',
        }
    }
 }

OR

const config = {
    redis: {
        client: RedisClientName.REDIS_V4,
        options: {
            socket: {
                host: "redis"
            }
        }
    }
 }

Indeed, do remember to give the config to the Producer, Consumer constructors as well as QueueManager.createInstace() method.

Hope that helps =)