生产环境中transactionScope和ServiceBus的问题 [英] Problems with transactionScope and ServiceBus in production environment

查看:81
本文介绍了生产环境中transactionScope和ServiceBus的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了其他类似的问题,但是我还没有找到可行的解决方案.

I have seen other with similar issues but I have yet to find a working solution.

我在调用数据库和ServiceBus时正在使用事务.

I'm using a transaction while calling Database and ServiceBus.

我正在为数据库使用UnitOfWork/EntityFramework.

I'm using a UnitOfWork/EntityFramework for my database.

这是我的代码

/*Creating the list and adding to UnitOfWork repository*/
....
using (TransactionScope scope = new TransactionScope())
        {
            _unitOfWork.Save();
            ExportGroups(myGroupList);
            scope.Complete();
        }

这是ExportGroups函数的一个片段

And here is a snippet from the ExportGroups function

public void ExportGroups(IEnumerable<Group> groups)
{
     /*Generating BrokeredMessage message*/
     Task.Factory.StartNew(() =>
        {
            MessagingFactory factory = CreateMessagingFactory(...);
            if (factory != null)
            {
                var sender = factory.CreateMessageSender(topicName);
                sender.Send(message);
            }
        }).Wait();

}

这在我的开发环境中没有任何问题.但是当我们将其投入生产时,会出现以下错误

This works without any issues in my development environment. But when we put it into production I get the following error

"System.InvalidOperationException:其他资源管理器/DTC不支持本地事务."

"System.InvalidOperationException: Local transactions are not supported with other resource managers/DTC."

在机器上启用了DTC,我们用它来处理其他事务也很好,尽管它们中没有一个使用ServiceBus.

The DTC is enabled on the machine and we use it to process other transactions just fine, though none of them use the ServiceBus in them.

Server stack trace: 
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpResourceManager.EnlistAsyncResult..ctor(SbmpResourceManager resourceManager, Transaction transaction, IRequestSessionChannel channel, SbmpMessageCreator messageCreator, Action`1 partitionInfoSetter, TimeSpan timeout, AsyncCallback callback, Object state)
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpResourceManager.BeginEnlist(Transaction transaction, IRequestSessionChannel channel, SbmpMessageCreator messageCreator, Action`1 partitionInfoSetter, TimeSpan timeout, AsyncCallback callback, Object state)
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<>c__DisplayClass3e.<GetAsyncSteps>b__38(TIteratorAsyncResult thisPtr, TimeSpan t, AsyncCallback c, Object s)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.Start()

Exception rethrown at [0]: 
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnEndSend(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state)

Exception rethrown at [1]: 
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.RunSynchronously()
   at Microsoft.ServiceBus.Messaging.MessageSender.Send(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout)
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at ....GroupService.ExportGroups(IEnumerable<Group> groups)

推荐答案

不同的Windows Azure服务之间不支持事务.也就是说,有许多

Transactions are not supported across different Windows Azure Services. That said there are many ways to send messages to service bus with transactional guarantees.

HTH!斯里

这篇关于生产环境中transactionScope和ServiceBus的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆