RamosLi / dbay-apns-for-java

High performance Java client for APNS(Apple Push Notification Service)
Apache License 2.0
238 stars 152 forks source link

跪求作者答疑 #13

Open qysnowqy opened 9 years ago

qysnowqy commented 9 years ago
 作者,您好,我基于您的apns4j,写了一个ios推送应用。
 主程序不断读取queue中的数据。有数据推,否则休息。
 遇到了一些情况。希望您赐教
 1.ApnsConnectionImpl中推一条输出日志,再推不输出日志
 2.输出日志的时候,测试机器都收到,不输出日志的时候个别测试机收到

  以下是我的代码
            IApnsService service = getApnsService();
    new Thread(new DelFailTokenThread(service)).start();
    int sleep = 0;
    int timeSleepCount = 0;
    while (true) {
        try {
            payment = (QueuePushPayment) memcachedClient.get(queue);
            if (payment == null) {
                if (sleep < sleepCount) sleep++;
                logger.info("push thread is   sleepCount=" + sleep);
                if(sleep == sleepCount){
                    sleep = 0;
                    try {
                        Thread.sleep(60000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else{
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            } else {
                timeSleepCount++;
                if (sleep > 0)  sleep--;
                Payload payload = getPayload(payment.getPayload());
                service.sendNotification(payment.getDeviceToken(), payload);
                payload = null;
                if (timeSleepCount  == 10000) {
                    timeSleepCount = 1;
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
RamosLi commented 9 years ago

通过现在的信息很难去判断到底问题出在哪儿 建议你在sendNotification之前打一条log,然后再跟ApnsConnectionImpl中输出的log一一比对下,看是否能对应的上。

如果用log4j的话,可以这么配下

qysnowqy commented 9 years ago

感谢您的答复。请问您的每天百万推送一般设置线程池大小为多少?

RamosLi commented 9 years ago

为了避免单点,我在两台机器上搭了APNS的推送服务,poolSize设的是12,每台机器每天各自发送100多万条通知,CPU和内存消耗都特别低。

qysnowqy commented 9 years ago

再次感谢。那个log不输出的问题我定位了。 dev-3 Received error response. status: 8, id: 180, error-desc: Invalid token 有这个info输出的时候,下次推送就不会出现info日志了。 请问这个token是失效的吗?如果是失效的,feedbackservice没有返回。 这个应该是错误token吧?