successCallback没有被调用timeToken

时间:2014-11-25 10:54:53

标签: java pubnub

我在下面写了一个简单的程序,用Java中的pubnub接收消息。我遇到的问题是我无法检索收到的邮件的timetoken。尽管它存在于API

中,但从未调用此回调
 @Override
                public void successCallback(String channel, Object message, String timeToken){
                   System.out.println("SUBSCRIBE : " + channel + " : " + message.getClass() + " : " + message.toString());
                   System.out.println(timeToken);
                }    

虽然调用了没有timetoken的回调。任何人都可以告诉我如何检索信息的时间码。

import java.io.IOException;

    import com.pubnub.api.*;

import org.json.*;

public class Main{

   public static void main(String[] args){

      Pubnub pubnub =
         new Pubnub("demo", "demo");

      pubnub.setUUID("1");

      try{
         pubnub.subscribe("test", 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);
            }


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

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

         });

         pubnub.history("akosha1", 100, new Callback(){

            public void successCallback(String channel, Object response){
               System.out.println(response.toString());
            }

            public void errorCallback(String channel, PubnubError error){
               System.out.println(error.toString());
            }

         });

         try{
            System.in.read();
         } catch (IOException e){
            // TODO Auto-generated catch block
            e.printStackTrace();
         }

      } catch (PubnubException e){
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

}

2 个答案:

答案 0 :(得分:3)

此API已添加到最新的PubNub Java SDK v3.7.2(或更高版本)中。 https://github.com/pubnub/java/tree/master/java

答案 1 :(得分:2)

您可以通过自己构建java sdk jar并更改文件PubnubCore.java并将行号2617更改为此来轻松获得timetoken:

if (!isWorkerDead(hreq)) 
                callback.successWrapperCallback(channel, PubnubUtil.parseJSON(message), timeToken);

再次构建pubnub jar。

然后你可以打电话

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

如果你想跳过这个过程,我可以分享更新的jar。