2011-01-20 10 views
8

私は誰かが私を助けることができることを望むこの記事をここに書いています。NServiceBus MSDTCの苦境

NServiceBusをASP.NET MVCアプリケーションに実装しようとしています。私は、すべてのことが正しく行われていることを確認するために、一歩一歩一歩進みました。私は、LinqからSQLへのクエリを実行してジョブを検索し、アラートを電子メールするハンドラにジョブIDを渡すイベントを持っています。このプロセスは非常に簡単です。

しかし、私の人生で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 

すべてが素晴らしい作品。示すように

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) 

私はDTCピングを試してみましたが、それが成功したという事実MSDTC ISN」のように私は知っている作品問題はありません。私はNHibernateがNServiceBusと同様の問題を抱えていたが、LINQ to SQLを使って同じことをすることはできなかったと読んだ。

この件に関するお手伝いをさせていただきます。

+0

ローカルボックスのデータベースでこれを試してみると、すべてがうまくいくようです。今はリモートボックス上のデータベースではうまくいかない理由が非常に不思議です。 –

+0

ハンドラマシンとデータベースマシンの両方のOSは何ですか?データベースマシンはインバウンドトランザクションを許可していますか?ハンドラマシンとDBマシンの両方でDTCに設定されている認証メカニズムは何ですか? –

答えて

10

私は同様の問題があり、原因がNServiceBusよりLINQ-to-SQLの方が多いことがわかりました。スタックトレースを見ると、NSBではなく、LINQおよびSqlClientライブラリが根本的な原因であることがわかります。私が使い終わったソリューションは、あなたのデータアクセスがトランザクションであることの重要性に応じて、あなたのために働くかもしれませんし、LINQ to SQLコードのトランザクションを明示的に無効にすることでした。私の場合、私は単純に、このようなコードで、SQLにLINQを使用してストアドプロシージャを呼び出していました:

 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汎用ホスト)の私のソリューションで動作しています。

+0

非常に興味深い観察。データアクセスシナリオではTransactionScopeを使用しません。必要に応じてLinq取引を使用します。もちろん、私たちはNSBで使用しているアイテムについては実際に取引をする必要はありませんが、状況が発生した場合にどのように活用できるのか不思議です。本当に問題がLINQ内で嘘をついたときにMSDTCを構成しようとしていました。明らかに、私はそれを使用していなかったので、TransactionScopeを考えなかった。 –

1

私はMSDTCに問題があることを覚えていますが、私の人生は私がこの問題を解決するために参照したブログ/投稿/を見つけることができません。とにかく、そのpingプログラムが動作している場合、それは少し奇妙です。私は追加することが1つの提案は、ちょうど.CreateBus()行の前に、行を追加し

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

をしようとしています。サブスクリプションを使用している場合は、サブスクリプションにトランザクションの使用を停止するよう指示されます。これは問題の可能性があります。ただし、これを行うと警告が表示されるため、購読の信頼性が低下するため、重大な状況では使用しないでください。

6

NServiceBusをサーバーとして設定していることがわかります。つまり、です。私はあなたがここにいるのは、トランザクショナルサーバーにメッセージを送信している非トランザクションのWebアプリケーションだと思います。

+1

エンドポイントAsA_Serverにマークを付けると、IsTransactional(true)と同等です。これは実際に設定したIsTransactional(false)を上書きします。おそらく@AnupMarwadi、あなたは 'AsA_Client'としてエンドポイントをマークする必要がありますか? –

11

実際に問題が解決された解決策はありますか? DTCPingツールを使用してMSDTCを正しくセットアップし、根底にある問題を見つけることをお勧めします。

は、詳細については、この記事をチェックアウト:

をMSDTCは、幸運はかなりあいまいです!

関連する問題