jedis pubsub 和超时:如何以订阅者的身份无限收听? [英] jedis pubsub and timeouts: how to listen infinitely as subscriber?

查看:64
本文介绍了jedis pubsub 和超时:如何以订阅者的身份无限收听?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力创建一个 Jedis 客户端的概念,该客户端作为 Redis pubsub 频道的订阅者无限地侦听并在消息进来时处理它们.

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.

我的问题是,在一段时间不活动后,服务器停止无声响应.我认为这是由于我订阅的 Jedis 客户端发生超时.

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.

真的会这样吗?如果是这样,有没有办法将这个特定的 Jedis 客户端配置为不超时?(而其他 Jedispool 不受某些全局设置超时的影响)或者,是否有另一种(最佳实践)方式来实现我的目标?

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) :

在网络服务器启动期间执行:

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) {
          ...
        }
    }

谢谢.

推荐答案

ermmm,下面解决了所有问题.确实这是绝地武士的事情

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();
}

这篇关于jedis pubsub 和超时:如何以订阅者的身份无限收听?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆