zhangkaitao / es

JavaEE项目开发脚手架(我的公众号:kaitao-1234567,我的新书:《亿级流量网站架构核心技术》)
https://github.com/zhangkaitao/es
Apache License 2.0
2.17k stars 1.59k forks source link

push 体验 #19

Closed caizhengda closed 10 years ago

caizhengda commented 11 years ago

项目安装的时,某些依赖下载遇到点问题,mvn setting.xml 代理搞定。 访问项目:http://localhost:9080/es-web/admin/index 看到了push, 轮询的实现方式。但发现体验不是很好。 例如操作: forefox debug 监控 请求:http://localhost:9080/es-web/admin/polling?_=1376311472481 --> 实例管理:Excel导入导出, --> 添加了一条数据。 --> 导出Excel 2007(推荐)

当没有 admin/polling 请求的时候导出Excel, push消息不会及时的提醒,然后等到下一个admin/polling 请求 开始到结束, 在不查看消息列表的情况下依然不会有弹出提醒。

caizhengda commented 11 years ago

excel 导出下载地址问题 点击下载

快捷消息窗口: firefox:http://localhost:9080/es-web/admin/{ctx}\upload\excel\admin\excel_20130812210651947.xlsx

chrome:http://localhost:9080/es-web/admin/{ctx}/upload/excel/admin/excel_20130812210651947.xlsx

zhangkaitao commented 11 years ago

这个有bug,最近比较忙,没有把最新的上传,你可以使用如下配置来修正

你可以把spring-mvc.xml的

    <mvc:async-support default-timeout="35000" task-executor="executor"/>

超时时间设置的比 js中稍微长点 这样我测了下没有503了;

js 我稍微改了下

var timeout = 30 * 1000; var defaultRetryTime = 10 * 1000; var retryTime = defaultRetryTime; var pollingUrl = ctx + "/admin/polling"; var longPolling = function(url, callback) { $.ajax({ url: url, async: true, cache: false, global: false, timeout: timeout, dataType : "json" }).done(function(data, status, request) { callback(data); data = null; status = null; request = null; var currentRetryTime = 0; setTimeout( function () { longPolling(url, callback); }, currentRetryTime ); }).fail(function(jqXHR, textStatus, errorThrown) { jqXHR = null; textStatus = null; errorThrown = null;

                var currentRetryTime = 0;
                if(textStatus == 'error' || textStatus == 'parsererror') {
                    retryTime = retryTime * 2;
                    if(retryTime >= 1000 * 1000) {
                        retryTime = defaultRetryTime;
                    }
                }

                setTimeout(
                    function () {
                        longPolling(url, callback);
                    },
                    currentRetryTime
                );
            });
    };

如果是error 那么重试时间是递增的;否则比如timeout 直接重试 不暂停(否则可能有延迟) 就像之前说的

caizhengda commented 11 years ago

(function getMessages() {
     $.ajax(
    {
        dataType : "json",
        url : 'getMessages',
        cache : false,
        success : function(data) {
            //do something
        }
    }).always(function() {
        getMessages();
    });
})();


这样的方式不知道是否可行,
caizhengda commented 11 years ago

为了防止 http status 非 200 , (也就是我个人看个debug控制台请求红色特别扭, 强迫症 呵呵)


dr.onTimeout(new Runnable() {
    @Override
        public void run() {
       // TODO Auto-generated method stub
         }
});


我有空就看看java , 借鉴涛哥的代码复习+学习.
zhangkaitao commented 11 years ago

记录那个红色的部分是浏览器完成的,咱控制不了