美文网首页
异步回调

异步回调

作者: 杜子龙 | 来源:发表于2019-01-02 15:21 被阅读0次

    调用方在调用本接口时,会在接口地址后跟回调地址,然后提供方立刻返回一个结果,并启动一个线程执行业务逻辑,执行完后请求回调地址,实现异步回调,这里只给出提供方demo:

        @ApiOperation(value = "自动同步权限")
        @RequestMapping(value = "/auto_synchronize_permission", method = RequestMethod.POST)
        @ResponseBody
        public TestResult autoSynchronize(HttpServletRequest httpServletRequest){
            String callback = httpServletRequest.getParameter("callback");//回调url
            new Thread(){
                public void run(){
                    TestResult testResult = testPermissionCategoryService.autoSynchronize();//具体实现
                    JSONObject request =new JSONObject();
                    request.put("result", testResult);
                    try {
                        String res = HttpClientUtil.doPostJson(callback, request.toJSONString(), null);
                        log.info(res);
                    } catch (Exception e) {
                        log.info(e.getMessage(), e);
                    }
                }
            }.start();
            return new TestResult(BaseMessage.SUCCESS);
        }
    

    相关文章

      网友评论

          本文标题:异步回调

          本文链接:https://www.haomeiwen.com/subject/rquvlqtx.html