Class PubSubSubscriber

java.lang.Object
redis.clients.jedis.JedisPubSub
com.reve.balancemanager.pubsub.PubSubSubscriber
All Implemented Interfaces:
Runnable

public class PubSubSubscriber extends redis.clients.jedis.JedisPubSub implements Runnable
Subscriber class to subscribe and listen to messages in Redis cluster pubsub
  • Constructor Summary

    Constructors
    Constructor
    Description
    PubSubSubscriber(BalanceManager balanceManager, redis.clients.jedis.JedisCluster jedisCluster, String[] channels)
    Create an instance of Runnable to subscribe on the given channels.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onMessage(String channel, String message)
    Process the message received from the given channel.
    void
    onSubscribe(String channel, int subscribedChannels)
    Process on subscribe successful event.
    void
    onUnsubscribe(String channel, int subscribedChannels)
    Process on subscribe successful event.
    void
    run()
    Thread run method.

    Methods inherited from class redis.clients.jedis.JedisPubSub

    getSubscribedChannels, isSubscribed, onPMessage, onPong, onPSubscribe, onPUnsubscribe, ping, ping, proceed, proceedWithPatterns, psubscribe, punsubscribe, punsubscribe, subscribe, unsubscribe, unsubscribe

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PubSubSubscriber

      public PubSubSubscriber(BalanceManager balanceManager, redis.clients.jedis.JedisCluster jedisCluster, String[] channels)
      Create an instance of Runnable to subscribe on the given channels.
      Parameters:
      balanceManager - Instance of BalanceManager who will process the received messages from the subscribed channels.
      jedisCluster - Connection of JedisCluster to subscribe the redis channels.
      channels - The redis channels to whom this PubSubSubscriber will subscribe.
  • Method Details

    • run

      public void run()
      Thread run method.
      Specified by:
      run in interface Runnable
    • onMessage

      public void onMessage(String channel, String message)
      Process the message received from the given channel.
      Overrides:
      onMessage in class redis.clients.jedis.JedisPubSub
      Parameters:
      channel - The channel, where the message is received.
      message - The received message.
    • onSubscribe

      public void onSubscribe(String channel, int subscribedChannels)
      Process on subscribe successful event. Whenever a subscription is successful, this method will be called, to notify the event.
      Overrides:
      onSubscribe in class redis.clients.jedis.JedisPubSub
      Parameters:
      channel - The channel, where subscription is successful.
      subscribedChannels - Total number of channels this JedisPubSub instance has successfully subscribed so far.
    • onUnsubscribe

      public void onUnsubscribe(String channel, int subscribedChannels)
      Process on subscribe successful event. Whenever a subscription is successful, this method will be called, to notify the event.
      Overrides:
      onUnsubscribe in class redis.clients.jedis.JedisPubSub
      Parameters:
      channel - The channel, where un-subscription is successful.
      subscribedChannels - Total number of channels this JedisPubSub instance has successfully subscribed so far.