简体   繁体   中英

Error when handling NServiceBus Subscription messages

After adding logging (using log4net) to my application, it no longer handles subscription messages correctly and puts them on to the error queue. Below, some namespace names have been changed to protect the innocent.

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>

I've also changed the Endpoint config to this:

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");
    }
}
}

When it fires up, any subscription message received gets dumped onto the error queue and I see this in the log:

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.

This is due to a bug in RC4, please try it with
RC5 and see if that fixes the issue.

I have found one cause of the error/problem. If the message forwarding queue is specified in the app.config (ForwardReceivedMessagesTo) but the queue does not exist on the host machine then you will get the same error.

app.config

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

The problem was caused as only one process out of the six I've got running named the missing queue in the Test environment. Five were set to 'auditqueue' and one was 'auditqueue_test2' which, sadly was the correct name except it didn't exist and it does not auto-create the queue in this instance nor make any remark in the DEBUG statements that this is the problem.

I created a new transactional queue called 'auditqueue_test2' and it's now running. I'm going to add in the logging again and see if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM