如果我使用单个 pubnub 实例多次订阅一个频道会发生什么?
What will happen if i subscribe multiple times a channel with single pubnub instance?
如果我用一个pubnub实例多次订阅了一个频道是否会订阅,如果订阅了会执行哪个回调?
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());
}
}
);
如果我用一个pubnub实例多次订阅了一个频道是否会订阅,如果订阅了会执行哪个回调?
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());
}
}
);