zoukankan      html  css  js  c++  java
  • spring事务手动回滚

    @Transactional(rollbackFor = { Exception.class })
    public JSONObject preSendMsg(AuthInfo authInfo, Message message) {
            JSONObject jsonObject = new ResultJSONObject("000", "消息预发送成功");
            try {
                // 判断参数有效性
                if (null == authInfo || StringUtil.isEmpty(authInfo.getUsername()) || StringUtil.isEmpty(authInfo.getPassword())
                        || null == message || StringUtil.isEmpty(message.getQueueName())
                        || StringUtil.isEmpty(message.getExchange()) || StringUtil.isEmpty(message.getContent())) {
                    return new ResultJSONObject("001", "重要参数不可为空!");
                }
                // 检查消息操作的权限信息
                // 检查队列配置是否存在 1
                JSONObject checkAuthJson = this.checkAuthInfo(authInfo, message.getQueueName());
                if (!"000".equals((String) checkAuthJson.get("resultCode"))) {
                    return checkAuthJson;
                }
                Map<String, Object> mqInfo = checkAuthJson.getJSONObject("mqInfo");
    
                // 检查消息的发送频率,控制流速...TODO
                // 消息去重,相同消息返回相同的msgId 2
                if (!chechMsgUnique(mqInfo, message)) {
                    return new ResultJSONObject("021", "消息内容重复!");
                }
                // 保存消息 3
                MessageTpl messageTpl = saveMessage(mqInfo, message);
                if(null==messageTpl){
                    return new ResultJSONObject("031", "消息保存失败!");
                }
                jsonObject.put("msgId", messageTpl.getMsgId().toString());
            } catch (Exception e) {
                logger.error("preSendMsg_Exception ", e);
                jsonObject=new ResultJSONObject("preSendMsg_Exception", "消息预发送异常");
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动开启事务回滚
            }
            return jsonObject;
        }
  • 相关阅读:
    获取Unity和UGUUI内置组件的属性名
    Sqlite管理工具
    C#对象属性浅拷贝和深拷贝
    fbx查看软件
    如何区分Unity国内版和国际版
    Unity2019及Unity2020打包android的环境配置
    提高Unity编译dll的速度
    SpringBoot使用swagger
    SpringBoot 使用 Interceptor 拦截器
    SpringBoot 使用 Filter 过滤器
  • 原文地址:https://www.cnblogs.com/xujishou/p/6210289.html
Copyright © 2011-2022 走看看