首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NServiceBus MSDTC问题

NServiceBus MSDTC问题
EN

Stack Overflow用户
提问于 2011-01-20 17:04:03
回答 4查看 8.7K关注 0票数 8

我在这里写这篇文章,希望有人能帮助我。

我正在尝试在ASP.NET MVC应用程序上实现NServiceBus。我已经完成了每一个步骤,以确保一切都是正确的。我有一个将Job Id传递给我的处理程序的事件,该处理程序随后执行Linq- to -Sql查询,查找作业,然后通过电子邮件发送警报。这个过程非常简单。

然而,我无论如何也不能让MSDTC工作。我一直收到以下错误:

下面是我如何配置我的总线:

代码语言:javascript
复制
 Bus = NServiceBus.Configure.WithWeb()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();

我没有使用事务,所以我知道MSDTC甚至不应该被调用。

我的Handler代码如下:

代码语言:javascript
复制
public void Handle(ApplyJobMessage message)
    {
        if (message != null)
        {
            using(var context = new MyContext())
            {
                JobPosting posting = (from c in context.JobPostings
                 where c.JobPostingId == message.JobId
                 select c).SingleOrDefault();
            }

端点配置如下:

代码语言:javascript
复制
public class MessageEndpoint : IConfigureThisEndpoint, AsA_Server, IWantToRunAtStartup

一切都很好。当我这样做时,消息会正确到达:

代码语言:javascript
复制
Bus.Send(message);

但是,出现MSDTC错误,如下所示:

代码语言:javascript
复制
    2011-01-20 00:55:09,744 [Worker.5] ERROR NServiceBus.Unicast.UnicastBus [(null)]
 <(null)> - JobApplicationHandler Failed handling message.
System.Runtime.InteropServices.COMException (0x8004D02A): The MSDTC transaction
manager was unable to push the transaction to the destination transaction manage
r due to communication problems. Possible causes are: a firewall is present and
it doesn't have an exception for the MSDTC process, the two machines cannot find
 each other by their NetBIOS names, or the support for network transactions is n
ot enabled for one of the two transaction managers. (Exception from HRESULT: 0x8
004D02A)
   at **System.Transactions.Oletx.ITransactionShim.Export**(UInt32 whereaboutsSize,
Byte[] whereabouts, Int32& cookieIndex, UInt32& cookieSize, CoTaskMemHandle& coo
kieBuffer)
   at System.Transactions.TransactionInterop.GetExportCookie(Transaction transac
tion, Byte[] whereabouts)
2011-01-20 00:55:09,749 [Worker.5] WARN  NServiceBus.Unicast.Transport.Msmq.Msmq
Transport [(null)] <(null)> - Failed raising 'transport message received' event
for message with ID=9cb4b136-e110-4b87-81f6-ee4cd3fcaf46\6151
System.Reflection.TargetInvocationException: Exception has been thrown by the ta
rget of an invocation. ---> System.Transactions.TransactionManagerCommunicationE
xception: Communication with the underlying transaction manager has failed. --->
 System.Runtime.InteropServices.COMException (0x8004D02A): The MSDTC transaction
 manager was unable to push the transaction to the destination transaction manag
er due to communication problems. Possible causes are: a firewall is present and
 it doesn't have an exception for the MSDTC process, the two machines cannot fin
d each other by their NetBIOS names, or the support for network transactions is
not enabled for one of the two transaction managers. (Exception from HRESULT: 0x
8004D02A)
   at System.Transactions.Oletx.ITransactionShim.Export(UInt32 whereaboutsSize,
Byte[] whereabouts, Int32& cookieIndex, UInt32& cookieSize, CoTaskMemHandle& coo
kieBuffer)
   at System.Transactions.TransactionInterop.GetExportCookie(Transaction transac
tion, Byte[] whereabouts)
   --- End of inner exception stack trace ---
   at System.Transactions.TransactionInterop.GetExportCookie(Transaction transac
tion, Byte[] whereabouts)
   at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transacti
on transaction, Byte[] whereAbouts)
   at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
   at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
   at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transa
ction)
   at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transacti
on transaction)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection ownin
gObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow
ningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou
terConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionU
ser user)
   at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
   at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider
.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Express
ion expression)
   at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)

我已经尝试过DTC ping,它成功地工作了,所以我知道MSDTC不是问题所在。我读到过NHibernate与NServiceBus有类似的问题,但我还无法将其与LINQ to SQL相提并论。

在这个问题上的任何帮助都将是非常感谢的。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-01-23 22:49:45

我遇到了类似的问题,发现原因更多的是LINQ-to-SQL,而不是NServiceBus。如果你查看你的堆栈跟踪,你会发现根本原因是你的LINQ和SqlClient库,而不是NSB。我最终使用的解决方案是显式关闭我的LINQ to SQL代码中的事务。这个解决方案可能对您有效,也可能不适用,这取决于数据访问对于事务性的重要性。在我的例子中,我只是使用LINQ to SQL调用一个存储过程,代码如下:

代码语言:javascript
复制
        public void Save(SomeEvent someEvent)
        {
            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                _loggingDatabaseConnection.DataContext.log_ClickInsert(
someEvent.LogDate, 
someEvent.Id, 
someEvent.OtherStuffGoesHere);
            }

这里最重要的部分是TransactionScope和TransactionScopeOption.Suppress。这确保了LINQ to SQL不会尝试将调用登记到使用DTC的事务中。这在我的消息处理程序(NServiceBus通用主机)中的解决方案中有效。

票数 10
EN

Stack Overflow用户

发布于 2011-06-07 00:29:05

公认的解决方案实际上是问题的变通方法。我建议你使用DTCPing工具来正确设置MSDTC,并找到潜在的问题。

有关更多信息,请查看此帖子:

  • Troubleshooting MSDTC issues with the DTCPing tool
  • Conquering NServiceBus part 5 – Troubleshooting DTC
  • Troubleshooting MSDTC, RPC and NServiceBus issues

MSDTC相当晦涩难懂,祝你好运!

票数 12
EN

Stack Overflow用户

发布于 2011-01-23 16:05:28

我注意到,您正在将NServiceBus配置为服务器,这意味着它是事务性的。我认为你在这里有一个非事务性的web应用程序,它向事务性服务器发送消息。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4745157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档