如果我使用单个pubnub实例多次订阅某个频道,会发生什么?

时间:2015-09-15 10:50:41

标签: android pubnub

如果我用单个pubnub实例多次订阅了一个频道,它是否会订阅,如果它订阅了哪个回调将被执行?

1 个答案:

答案 0 :(得分:7)

PubNub订阅connectCallback行为

成功订阅频道后,系统会调用connectCallback

在此之后,每当您致电subscribe到其他渠道时,系统都会调用connectCallback

但如果您订阅了您已订阅的频道,则connectCallback将不会被调用(基本上是无操作)。

Sample Java/Android subscribe code

pubnub.subscribe("my_channel", new Callback() {

          @Override
          public void connectCallback(String channel, Object message) {
              System.out.println("SUBSCRIBE : CONNECT on channel:" + channel
                         + " : " + message.getClass() + " : "
                         + message.toString());
          }

          @Override
          public void disconnectCallback(String channel, Object message) {
              System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
                         + " : " + message.getClass() + " : "
                         + message.toString());
          }

          public void reconnectCallback(String channel, Object message) {
              System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
                         + " : " + message.getClass() + " : "
                         + message.toString());
          }

          @Override
          public void successCallback(String channel, Object message) {
              System.out.println("SUBSCRIBE : " + channel + " : "
                         + message.getClass() + " : " + message.toString());
          }

          @Override
          public void errorCallback(String channel, PubnubError error) {
              System.out.println("SUBSCRIBE : ERROR on channel " + channel
                         + " : " + error.toString());
          }
      }
);