adjust / rmq

Message queue system written in Go and backed by Redis
MIT License
1.57k stars 206 forks source link

Trying to use rmq against a clustered Redis/Elasticcache Db. keep getting the "MOVED" error. #110

Closed afernandezod closed 10 months ago

afernandezod commented 3 years ago

After reading the "MOVED" error is due to instantiate a client to a clustered redis Db, I tried several options using redis.NewClusterCLienat, redis.NewClient and when ready to establish the connection I tried rmq.OpenConnectionWithRedisClient in order to once having the connection active be able to open the queue (rmq-connection.OpenQueue().

Not sure if I am missing something or clustered redis Db are not in the scope for rmq.

Any help is greatly appreciated.

Here part of the code:

func redisConnect(quename string) rmq.Queue {
    redisClient := redis.NewClient(&redis.Options{
        Addr: Host,
        DB:   0,
    })

    nodes := strings.Split(Hosts, ",")
    c := redis.NewClusterClient(&redis.ClusterOptions{
        Addrs: nodes,
        NewClient: func(opt *redis.Options) *redis.Client {
            opt.Addr = Host
            opt.DB = 0
            return redis.NewClient(opt)
        },
    })

    ctx := context.Background()
    pingError := c.Ping(ctx).Err()

    if c.Ping(ctx).Err() != nil {
        panic("Unable to connect to redis ")
    }

    connection, err := rmq.OpenConnectionWithRedisClient("TCP", redisClient, nil)
    if err != nil {
        panic(err)
    }

    coolqueue, err := connection.OpenQueue(quename)
    if err != nil {
        panic(err)
    }

    return coolqueue
}

Thanks.

wellle commented 3 years ago

Hey, thanks for opening this issue. Unfortunately I have not been exposed to clustered Redis yet. And I don't think I will be able to set it up for testing anytime soon.

But can you add some more details as to where exactly you are seeing this error? Like in which operation is it being triggered? Thanks!

afernandezod commented 3 years ago

@wellle I appreciate your response. I already trying to create a new version of the Redis Db but not clustered to try again.

Basically the "MOVED...." error occurs during any of the rmq.open... .methods:

connection, err := rmq.OpenConnection("producer", "tcp", Host, 0, nil) or
connection, err := rmq.OpenConnectionWithRmqRedisClient("producer", redisClient, nil) or connection, err := rmq.OpenConnectionWithRedisClient("producer", redisClient, nil)

Obviously when RedisClient is needed I instantiate one: redisClient := redis.NewClient(&redis.Options{ Addr: Host, DB: 0, MaxRetries: 0, MinRetryBackoff: 0, MaxRetryBackoff: 0, DialTimeout: 0, ReadTimeout: 0, WriteTimeout: 0, PoolFIFO: false, PoolSize: 0, MinIdleConns: 0, MaxConnAge: 0, PoolTimeout: 0, IdleTimeout: 0, IdleCheckFrequency: 0, Limiter: nil, })

Hope this helps and will pay attention when clustered Db are available.

Thanks!!!!!!!

wellle commented 3 years ago

Thanks. Can you also show the full Redis error you are seeing? (please obfuscate any sensitive details if present)

afernandezod commented 3 years ago

The error has the following format:

MOVED <moved node's IP:port> (MOVED 7652 10.0.4.210:6379)

Here some of the links I read:

https://stackoverflow.com/questions/64374113/replyerror-moved-error-after-connecting-to-redis-cluster-aws

https://stackoverflow.com/questions/48232539/aws-redis-cluster-move-error

https://serverfault.com/questions/812156/redis-cluster-error-moved

https://aws.amazon.com/premiumsupport/knowledge-center/elasticache-redis-client-readonly/

si3nloong commented 3 years ago

I think it was your setup issue, try to amend your config as below

redis.NewClusterClient(&redis.ClusterOptions{ Addrs: nodes, })

afernandezod commented 3 years ago

@si3nloong Thanks. I tried that also and same results. I think as @wellle mentioned rmq hasn't been exposed to this flavor of clusters. As soon cloud/AWS team changed the condition from clustered to non-clustered, it worked.

QuanTran91 commented 2 years ago

So the rmq doest not support Redis in cluster mode? Do they?

wellle commented 2 years ago

Here's a related PR which is fairly close to complete. Maybe there's someone who could pick up this work and address the review comments so it can get merged? 🙏 https://github.com/adjust/rmq/pull/128

wellle commented 10 months ago

Again I'm not sure if this is still a problem. Closing for now. Please reopen if the problem still persists :v: