scredis / scredis

Non-blocking, ultra-fast Scala Redis client built on top of Akka IO.

Home Page:https://scredis.github.io/scredis/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scredis callback not registered

mayur-barge-incontact opened this issue · comments

I have a Redis cluster running in AWS, and i am using Redis pubsub in my actors.
In AWS I have two applications which use the same Redis host.
The first application runs without any issues. But for the second application

[�[37minfo�[0m] 2021-08-06 12:52:52,972 s.io.IOActor - Connecting to XXXX.cache.amazonaws.com/XXXX:6379
[�[37minfo�[0m] 2021-08-06 12:52:52,994 s.io.IOActor - Connected to XXXX.cache.amazonaws.com/10.0.4.11:6379 from /XXXX39716
[�[37minfo�[0m] 2021-08-06 12:52:53,038 s.i.SubscriberListenerActor - Subscribed to channel: Test-Channel
[�[37minfo�[0m] 2021-08-06 12:52:53,038 c.n.s.n.a.NodeManagerRedisSubscriberActor - Subscribed to Test-Channel channel successfully.

But my callback is never getting invoked.

Here is my client
Strangely though this client works with local redis
MyClient.txt


import akka.actor.{Actor, ActorLogging}
import scredis.{PubSubMessage, Redis}

import javax.inject.Inject
import scala.util.{Failure, Success}

object MyActor {
  val name = "my-actor"

  trait Factory {
    def apply(key: String): Actor
  }

  case class CreateRedisSubscription()
}

class MyActor @Inject()() extends Actor with ActorLogging {
  import MyActor._
  log.info(s"Started MyActor: ${this.self.path}")
  val channelName = "Test-Channel"

  val redisSubscriptionHandler: Function[PubSubMessage, Unit] = {
    case m: PubSubMessage.Subscribe => log.info(s"Subscribe ${m.channel} completed...")
    case m: PubSubMessage.Message =>
      log.debug(s"Received message on channel ${m.channel} with data ${m.readAs[String]()}")

    case _ => log.error("Unhandled message received.")
  }
  val redis: Redis = scredis.Redis(redisSubscriptionHandler)
  import redis.dispatcher

  override def receive: Receive = {
    case CreateRedisSubscription() =>
      redis.subscriber.subscribe(channelName).onComplete {
        case Success(count) =>
          log.info(s"Subscribed to $channelName channel successfully.")
        case Failure(e) =>
          log.error(s"Error occurred while Subscribing to channel: $channelName.",e)
      }

    case _ => log.error("Unhandled message received")
  }

  override def postStop(): Unit = {
    redis.subscriber.unsubscribe("Test-Channel")
    redis.quit()
  }
}

This callback case never gets invoked in AWS
case m: PubSubMessage.Subscribe => log.info(s"Subscribe ${m.channel} completed...")
But subscribe() Future returns successfully printing
[�[37minfo�[0m] 2021-08-06 12:52:53,038 c.n.s.n.a.NodeManagerRedisSubscriberActor - Subscribed to Test-Channel channel successfully.

But same code works fine in Local Redis server where both callback case logger and logger in actor both are printed