2011-12-22 20 views
5

Sto lottando con il concetto di creazione di un Jedi-client che sia in attesa all'infinito come un abbonato ad un canale PubSub Redis e gestisce i messaggi quando entrano in.jedis pubub e timeout: come ascoltare infinitamente come abbonato?

mio problema è che dopo un po 'di inattività delle fermate dei server rispondere silenziosamente. Penso che questo sia dovuto a un timeout che si verifica sul client Jedis con cui mi iscrivo.

Sarebbe davvero così? In tal caso, c'è un modo per configurare questo particolare client Jedis per non scadere? (Mentre altri Jedispools non sono interessati da un certo timeout impostato globalmente) In alternativa, c'è un altro (best practice) di ciò che sto cercando di ottenere?

Questo è il mio codice, (modificato/spogliata per la visualizzazione):

eseguito durante l'avvio del web-server:

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

Grazie.

risposta

6

ermmm, il sotto risolve tutto. Effettivamente era una cosa di Jedis

private AkkaStarter2(){ 
    //0 specifying no timeout.. Overlooked this 100 times 
    sub = new Jedis(REDISHOST, REDISPORT,0); 
    akkaListener = new AkkaListener(); 
}