2012-02-22 111 views
2

添加日誌(使用log4net的),我的應用程序後,當錯誤,它不再正確處理訂閱郵件,並將它們放在到錯誤隊列。下面,一些名稱空間名稱已被更改以保護無辜者。處理NServiceBus訂閱郵件

的app.config

<?xml version="1.0"?> 
<configuration> 
<configSections> 
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" /> 
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" /> 
    <section name="MsmqSubscriptionStorageConfig" type="NServiceBus.Config.MsmqSubscriptionStorageConfig, NServiceBus.Core" /> 
    <section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" /> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
</configSections> 

<Logging Threshold="INFO" /> 

<log4net> 
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> 
     <layout type="log4net.Layout.PatternLayout"> 
      <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/> 
     </layout> 
    </appender> 
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" > 
     <layout type="log4net.Layout.PatternLayout"> 
      <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/> 
     </layout> 
    </appender> 
    <appender name="TraceAppender" type="log4net.Appender.TraceAppender"> 
     <layout type="log4net.Layout.PatternLayout"> 
      <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/> 
     </layout> 
    </appender> 
    <appender name="FileAppender" type="log4net.Appender.FileAppender"> 
     <file value="logfile.txt" /> 
     <appendToFile value="true" /> 
     <layout type="log4net.Layout.PatternLayout"> 
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> 
     </layout> 
    </appender> 
    <root> 
     <level value="INFO"/> 
     <appender-ref ref="ConsoleAppender"/> 
     <appender-ref ref="FileAppender"/> 
    </root> 
</log4net> 

<MsmqTransportConfig 
    InputQueue="BankRequestDispatcherInputQueue_DEV2" 
    ErrorQueue="error" 
    NumberOfWorkerThreads="1" 
    MaxRetries="5" 
/> 

<UnicastBusConfig ForwardReceivedMessagesTo="auditqueue"> 
    <MessageEndpointMappings> 
     <add Messages="<assembly>.BankRequestBatchClosed,<assembly>" Endpoint="ScheduledBatchAgentInputQueue_DEV2" /> 
    </MessageEndpointMappings> 
</UnicastBusConfig> 

<MsmqSubscriptionStorageConfig Queue="BRDispatcher_DEV2_subscriptions" /> 

<!-- Neccessary for Fluent/NHibernate/SQLLite dlls --> 
<startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
</startup> 
<appSettings> 
    <add key="TempRequestFileLocation" value="c:\temp\"/> 
    <add key="KeepRequestFiles" value="true"/> 
    <add key="Environment" value="TEST"/> 
</appSettings> 
</configuration> 

我也改變了端點配置這樣:

namespace myNamespace.BRDispatcher 
{ 
    /// <summary> 
    /// Interface tells NServiceBus which roles to setup for this class. 
    /// </summary> 
    public class BRDEndpointConfig : IConfigureThisEndpoint, IWantCustomInitialization 
    { 
     #region Class References -1- 
     /// <summary> 
     /// Reference to Logger object. 
     /// </summary> 
     private static readonly ILog Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 
     #endregion 
    public void Init() 
    { 
     NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure); 

     Logger.Info("BankRequestDispatcher - Init()"); 

     NServiceBus.Configure.With() 
      //.Log4Net() 
      .DefaultBuilder() 
      .XmlSerializer() 
      .MsmqSubscriptionStorage() 
      .MsmqTransport() 
      .IsTransactional(true) 
      .PurgeOnStartup(false) 
      .UnicastBus() 
      .ImpersonateSender(false) 
      .LoadMessageHandlers() 
      .CreateBus() 
      .Start(); 

     Logger.Info("BankRequestDispatcher - Init() Complete"); 
    } 
} 
} 

當它激發起來,收到任何訂閱消息被傾倒到錯誤排隊,我看到這在日誌中:

2012-02-22 17:02:48,013 [Worker.8] ERROR NServiceBus.Unicast.Transport.Msmq.MsmqTransport [(null)] - Message has failed the maximum number of times allowed, ID=94b95c71-896f-4991-b3ba-9d2068a68c63\81504. 

回答

0

我已經找到了錯誤/問題的原因之一。如果在app.config(ForwardReceivedMessagesTo)中指定了消息轉發隊列,但隊列在主機上不存在,那麼您將得到相同的錯誤。

的app.config

<UnicastBusConfig ForwardReceivedMessagesTo="auditqueue"> 
<MessageEndpointMappings> 
    <add Messages="<assembly>.BankRequestBatchClosed,<assembly>" Endpoint="ScheduledBatchAgentInputQueue_DEV2" /> 
</MessageEndpointMappings> 

的問題,因爲只有一個進程引起了六個我有運行named在測試環境中缺少的隊列。五個被設置爲'auditqueue',另一個是'auditqueue_test2',可惜的是正確的名稱,除非它不存在,並且它不會在這個實例中自動創建隊列,也不會在DEBUG語句中做任何註釋,這就是問題。

我創建了一個名爲「auditqueue_test2」一個新的事務性隊列和它現在正在運行。我將再次添加日誌記錄並查看它是否有效。

1

這是由於在RC4一個bug,請
RC5嘗試一下,看看是否能解決問題。

+0

我沒有忘記提及我使用的是2.6版本。是否會升級到NSB 3.0? – Fellmeister 2012-02-22 22:21:41

+0

此外,記錄在調試工作正常,我的開發計算機上,但這些DLL的發佈版本有作爲與NServiceBus.Host.Exe – Fellmeister 2012-02-22 22:46:46

+0

服務運行應該是相當容易的試機的時候對這個問題(但預計一些破變化) – 2012-02-29 09:37:05