NServiceBus MSDTC的困境

NServiceBus MSDTC的困境,nservicebus,Nservicebus,我在这里写这篇文章是希望有人能帮助我 我正在尝试在ASP.NET MVC应用程序上实现NServiceBus。我已经经历了每一步,以确保一切都是正确的。我有一个事件,它将作业Id传递给我的处理程序,然后处理程序执行Linq到Sql查询,查找作业,然后通过电子邮件发送警报。这个过程非常简单 然而,我一辈子都不能让MSDTC工作。我不断发现以下错误: 以下是我如何配置总线: Bus = NServiceBus.Configure.WithWeb() .Log4Net()

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

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

然而,我一辈子都不能让MSDTC工作。我不断发现以下错误:

以下是我如何配置总线:

 Bus = NServiceBus.Configure.WithWeb()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();
我没有使用事务,所以我知道,MSDTC甚至不应该被调用

我的处理程序代码如下:

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();
            }
public class MessageEndpoint : IConfigureThisEndpoint, AsA_Server, IWantToRunAtStartup
端点的配置如下所示:

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();
            }
public class MessageEndpoint : IConfigureThisEndpoint, AsA_Server, IWantToRunAtStartup
一切都很好。当我执行以下操作时,消息正确到达:

Bus.Send(message);
但是,出现MSDTC错误,如图所示:

    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)
2011-01-20 00:55:09744[Worker.5]错误NServiceBus.Unicast.UnicastBus[(空)]
-JobApplicationHandler处理消息失败。
System.Runtime.InteropServices.COMException(0x8004D02A):MSDTC事务
管理器无法将事务推送到目标事务管理器
r由于通信问题。可能的原因是:存在防火墙,并且
MSDTC过程没有异常,两台机器无法找到
通过NetBIOS名称相互交换,或者对网络事务的支持为n
为两个事务管理器之一启用ot。(HRESULT的异常:0x8
004D02A)
在**System.Transactions.Oletx.ITransactionShim.Export**(UInt32-BoutsSize,
字节[]行踪、Int32和cookieIndex、UInt32和cookieSize、CoTaskMemHandle和coo
基辅(缓冲区)
在System.Transactions.TransactionInterop.GetExportCookie(Transaction transac
字节[]行踪)
2011-01-20 00:55:09749[Worker.5]警告NServiceBus.Unicast.Transport.Msmq.Msmq
传输[(null)]-引发“已接收传输消息”事件失败
对于ID为9cb4b136-e110-4b87-81f6-ee4cd3fcaf46\6151的消息
System.Reflection.TargetInvocationException:ta已引发异常
调用的目标。-->System.Transactions.TransactionManager通信
异常:与基础事务管理器的通信失败。-->
System.Runtime.InteropServices.COMException(0x8004D02A):MSDTC事务
管理器无法将事务推送到目标事务管理器
呃因为通讯问题。可能的原因是:存在防火墙,并且
MSDTC过程没有例外,这两台机器无法运行
通过他们的NetBIOS名称相互交换数据,或者支持网络事务
未为两个事务管理器之一启用。(来自HRESULT的异常:0x)
8004D02A)
在System.Transactions.Oletx.ITransactionShim.Export(UInt32-BoutsSize,
字节[]行踪、Int32和cookieIndex、UInt32和cookieSize、CoTaskMemHandle和coo
基辅(缓冲区)
在System.Transactions.TransactionInterop.GetExportCookie(Transaction transac
字节[]行踪)
---内部异常堆栈跟踪的结束---
在System.Transactions.TransactionInterop.GetExportCookie(Transaction transac
字节[]行踪)
在System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction)中
在事务上,字节[]行踪)
位于System.Data.SqlClient.SqlInternalConnection.EnclestNonNull(事务发送)
位于System.Data.SqlClient.SqlInternalConnection.Enlist(事务发送)
在System.Data.SqlClient.SqlInternalConnectionDS.Activate(事务处理
(行动)
在System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction
(交易时)
位于System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection ownin
gObject)
在System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection)中
(连接)
在System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection)中
terConnection、DbConnectionFactory(连接工厂)
在System.Data.SqlClient.SqlConnection.Open()处
位于System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionU
ser(用户)
在System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()处
位于System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()处
位于System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider
.Execute(表达式查询)
在System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Express
离子表达式)
位于System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1源)
我尝试过DTC ping,它成功地工作了,因此我知道MSDTC不是问题所在。我曾读到NHibernate在NServiceBus上也有类似的问题,但我无法将其与LINQ to SQL进行比较


非常感谢您在这件事上提供的任何帮助。

我记得自己在MSDTC上也遇到过问题,但我一生都找不到解决问题的博客/帖子/我引用的任何东西。不管怎样,如果ping程序正常工作,那就有点奇怪了。我可以补充的一个建议是尝试添加行

.RunCustomAction(() => 
  NServiceBus.Configure.Instance.Configurer.ConfigureProperty<MsmqSubscriptionStorage>(
  msg => msg.DontUseExternalTransaction, true))
.RunCustomAction(()=>
NServiceBus.Configure.Instance.Configurer.ConfigureProperty(
msg=>msg.DontUseExternalTransaction,真)

就在
.CreateBus()
行之前。如果您正在使用订阅,这将告诉订阅停止使用事务,这可能是您的问题。但是,请注意,这样做会降低订阅的可靠性,因此不要在关键情况下使用它。

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

我也有一个类似的问题,并发现原因更多地是LINQ to SQL,而不是NServiceBus。如果查看堆栈跟踪,您会发现根本原因是LINQ和SqlClient库,而不是NSB。我最终使用的解决方案可能有效,也可能无效