Question

I'm struggling with the concept of creating a Jedis-client which listens infinitely as a subscriber to a Redis pubsub channel and handles messages when they come in.

My problem is that after a while of inactivity the server stops responding silently. I think this is due to a timeout occurring on the Jedis-client I subscribe with.

Would this likely indeed be the case? If so, is there a way to configure this particular Jedis-client to not timeout? (While other Jedispools aren't affected with some globally set timeout) Alternatively, is there another (best practice) way of what I'm trying to achieve?

This is my code, (modified/ stripped for display) :

executed during web-server startup:

new Thread(AkkaStarter2.getSingleton()).start();

AkkaStarter2.java

   private Jedis sub;
   private AkkaListener akkaListener;

   public static AkkaStarter2 getSingleton(){
      if(singleton==null){
        singleton = new AkkaStarter2();
      }
      return singleton;
    }

    private AkkaStarter2(){
      sub = new Jedis(REDISHOST, REDISPORT);
      akkaListener = new AkkaListener();
    }

    public void run() {
      //blocking
      sub.psubscribe(akkaListener, AKKAPREFIX + "*");
    }

    class AkkaListener extends JedisPubSub {
        ....
        public void onPMessage(String pattern, String akkaChannel,String jsonSer) {
          ...
        }
    }

Thanks.

Était-ce utile?

La solution

ermmm, the below solves it all. Indeed it was a Jedis thing

private AkkaStarter2(){
  //0 specifying no timeout.. Overlooked this 100 times
  sub = new Jedis(REDISHOST, REDISPORT,0); 
  akkaListener = new AkkaListener();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top