博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TransactionScope 分布式事务
阅读量:7033 次
发布时间:2019-06-28

本文共 1077 字,大约阅读时间需要 3 分钟。

  /// 发送消息

         ///</summary>
       
///<param name="sendUserId"></param>
       
///<param name="toUser">格式7FFA3AF2-E74B-4174-8403-5010C53E49A7|userName,7FFA3AF2-E74B-4174-8403-5010C53E49A7|userName</param>
       
///<param name="content"></param>
       
///<param name="sendedStatus">表示已送</param>
       
///<returns></returns>
        publicstaticint sendMessage(string sendUserId, string toUser, string content, string sendedStatus)
       
{          
           
int receiveCount =0;
            TransactionOptions transactionOption
=new TransactionOptions();
           
//设置事务隔离级别
            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
           
// 设置事务超时时间为60秒
            transactionOption.Timeout =new TimeSpan(0, 0, 60);
           
using (TransactionScope scope =new TransactionScope(TransactionScopeOption.Required, transactionOption))
           
{
               
try
               
{
                   
//在这里实现事务性工作
    
//发送消息
                    insertMessage(sendUserId, toUser, content, sendedStatus);
    
//在接收信息表中插入记录
                    receiveCount += insertReceiveMessage(userids[0], sendUserId, content, "0");
                  
                   
// 没有错误,提交事务
                    scope.Complete();
                }
               
catch (Exception ex) {
                   
thrownew Exception("发送信息异常,原因:"+ex.Message);
                }finally{
                    //释放资源
                    scope.Dispose();
                  }
                              
            }
           
return receiveCount;
        }

转载地址:http://yrual.baihongyu.com/

你可能感兴趣的文章
Java Calendar类的使用总结
查看>>
LeetCode算法题-Perfect Number(Java实现)
查看>>
maven3.1安装及配置
查看>>
待人原则
查看>>
如何熟悉一个新项目
查看>>
2018年蓝桥杯java b组第二题
查看>>
结对-贪吃蛇游戏-测试过程
查看>>
实现Servlet容器一
查看>>
Python函数式编程指南(转)
查看>>
Spring4.x所有Maven依赖
查看>>
盒子变形-盒子加padding后 变形问题,
查看>>
小程序:在{{}}中使用函数
查看>>
Transporting Data Between Database
查看>>
android网络编程之HttpUrlConnection的讲解--上传大文件
查看>>
MySQL所学所思所想
查看>>
1、Filebeat概述
查看>>
助教第一次作业
查看>>
python04
查看>>
Json 数组传值
查看>>
Entity FrameWork 6帮助类
查看>>