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;
        }
  • 相关阅读:
    php字符串处理(邮件处理)
    phpstrtotime()对于31日求上个月有问题
    .net中linkbutton增加js验证
    excel 常用属性
    回车换行符总结
    视图增加自增id
    SQL优化索引、查询优化及分页算法方案
    js,cookies做悬浮购物车
    Server Application Unavailable出现的原因及解决方案集锦
    asp(javascript)中request.form("a").count 在ie6中总是为0
  • 原文地址:https://www.cnblogs.com/xujishou/p/6210289.html
Copyright © 2011-2022 走看看