事务型消息队列的一些注意事项

1、要想队列用事务必须创建事务型队列

MessageQueue.Create(Settings.Default.MQPath, true);

2、要有相应的权限设置 ,默认只能被创建消息队列的用户使用

MessageQueue.Create(Settings.Default.MQPath, true).SetPermissions("Everyone", MessageQueueAccessRights.FullControl);

 3、使用MessageQueu类的Send方法时必须以事务提交,不然发送不出去。使用Receive时可以不用事务接收

发送:

MessageQueueTransaction myTransaction = new MessageQueueTransaction();

// Begin the transaction.

myTransaction.Begin();

// Send the message.

myNewPrivateQueue.Send("My Message Data.", myTransaction);

// Commit the transaction.

myTransaction.Commit();

使用TransactionScope事务接收:

using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 20)))

{

Message m = mq.Receive(new TimeSpan(0, 0, 10), MessageQueueTransactionType.Automatic);

Console.WriteLine(m.Body);

ts.Complete();

}

备注:在Receive时加入等待时间可以防止线程阻塞,无法Abort线程

posted on 2008-03-08 22:05 Neo Devin 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/cuitao/archive/2008/03/08/1095715.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值