0

I am trying to use pub/sub impl. on Jedis to get information about master going down, but I am not sure how to subscribe to Sentinel channel.

My publisher class:

public Publisher(Jedis publisherJedis, String channels, String clusterName) {
    this.publisherJedis = publisherJedis;
    this.channels = channels;
    this.clusterName = clusterName;
}

public void start() {
    log.info("publishing on channel +odown");    
    try {
        while(true) {
            if(JedisPoolFactory.getMasterDown(clusterName)) {
                publisherJedis.publish("+odown", "master down, master down");
            }
        }
    } catch(Exception ex) {
        log.error("failure with end of stream catching.", ex);
    }
}

I have to register my sentinel as a publisher and all I need to do is decode the message every time there's a master failover. How do I then subscribe to sentinel channel?

Joe Jung
  • 47
  • 1
  • 7
  • 1
    I've no idea about Jedis, but Sentinel Pub/Sub works exactly like Redis Pub/Sub, so there is nothing special. You may want to try some basic Jedis Pub/Sub example using PSUBSCRIBE to `*` in order to get all messages to check if the basic works, then specialize the code to SUBSCRIBE only to the channels which are interesting for you. – antirez Jul 03 '15 at 09:21
  • 1
    UPDATE: read Redis docs more carefully :) Sentinels cannot be a publisher for any user-set channels, but it definitely publishes various monitoring conditions to channels bearing their names (e.g. +odown -> channel name is +odown) and other sentinel instance can simply subscribe for them. – Joe Jung Jul 09 '15 at 20:55

1 Answers1

0

As antirez said, you can connect to sentinel with normal Jedis instance, and subscribe channels. It is completely same to Redis pub/sub.

Jungtaek Lim
  • 1,638
  • 1
  • 12
  • 20
  • 감사합니다! 패키지 안에 클래스가 뭐뭐 있는지 앞으로는 더 주의깊게 보도록 하겠습니다 :) 혹시 문서화에 도움이 필요하시면 발벗고 도와드릴게요! – Joe Jung Jul 09 '15 at 20:56
  • 감사합니다! Jedis 깃허브 저장소에 위키 페이지가 편집 가능하게 열려 있으니 언제든 정리해 주시거나 이슈로 남겨 주세요 :) – Jungtaek Lim Jul 10 '15 at 11:33