/// <summary>
        /// Forward messages that have repeatedly failed to another endpoint.
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static Configure MessageForwardingInCaseOfFault(this Configure config)
        {
            if (ErrorQueue != null)
            {
                return(config);
            }
            if (SettingsHolder.Get <bool>("Endpoint.SendOnly"))
            {
                return(config);
            }

            ErrorQueue = Address.Undefined;

            var section = Configure.GetConfigSection <MessageForwardingInCaseOfFaultConfig>();

            if (section != null)
            {
                if (string.IsNullOrWhiteSpace(section.ErrorQueue))
                {
                    throw new ConfigurationErrorsException(
                              "'MessageForwardingInCaseOfFaultConfig' configuration section is found but 'ErrorQueue' value is missing." +
                              "\n The following is an example for adding such a value to your app config: " +
                              "\n <MessageForwardingInCaseOfFaultConfig ErrorQueue=\"error\"/> \n");
                }

                Logger.Debug("Error queue retrieved from <MessageForwardingInCaseOfFaultConfig> element in config file.");

                ErrorQueue = Address.Parse(section.ErrorQueue);

                config.Configurer.ConfigureComponent <FaultManager>(DependencyLifecycle.InstancePerCall)
                .ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);

                return(config);
            }


            var errorQueue = RegistryReader <string> .Read("ErrorQueue");

            if (!string.IsNullOrWhiteSpace(errorQueue))
            {
                Logger.Debug("Error queue retrieved from registry settings.");
                ErrorQueue = Address.Parse(errorQueue);

                config.Configurer.ConfigureComponent <FaultManager>(DependencyLifecycle.InstancePerCall)
                .ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);
            }

            if (ErrorQueue == Address.Undefined)
            {
                throw new ConfigurationErrorsException("Faults forwarding requires an error queue to be specified. Please add a 'MessageForwardingInCaseOfFaultConfig' section to your app.config" +
                                                       "\n or configure a global one using the powershell command: Set-NServiceBusLocalMachineSettings -ErrorQueue {address of error queue}");
            }

            return(config);
        }
示例#2
0
        /// <summary>
        /// Finds the configured error queue for an endpoint.
        /// The error queue can be configured in code using 'EndpointConfiguration.SendFailedMessagesTo()',
        /// via the 'Error' attribute of the 'MessageForwardingInCaseOfFaultConfig' configuration section,
        /// or using the 'HKEY_LOCAL_MACHINE\SOFTWARE\ParticularSoftware\ServiceBus\ErrorQueue' registry key.
        /// </summary>
        /// <param name="settings">The configuration settings of this endpoint.</param>
        /// <returns>The configured error queue of the endpoint.</returns>
        /// <exception cref="Exception">When the configuration for the endpoint is invalid.</exception>
        public static string ErrorQueueAddress(this ReadOnlySettings settings)
        {
            string errorQueue;

            if (settings.TryGet("errorQueue", out errorQueue))
            {
                Logger.Debug("Error queue retrieved from code configuration via 'EndpointConfiguration.SendFailedMessagesTo().");
                return(errorQueue);
            }

            var section = settings.GetConfigSection <MessageForwardingInCaseOfFaultConfig>();

            if (section != null)
            {
                if (!string.IsNullOrWhiteSpace(section.ErrorQueue))
                {
                    Logger.Debug("Error queue retrieved from <MessageForwardingInCaseOfFaultConfig> element in config file.");
                    return(section.ErrorQueue);
                }

                throw new Exception(
                          @"'MessageForwardingInCaseOfFaultConfig' configuration section is found but 'ErrorQueue' value is empty.
Take one of the following actions:
- set the error queue at configuration time using 'EndpointConfiguration.SendFailedMessagesTo()'
- Add a valid value to to the app.config. For example:
 <MessageForwardingInCaseOfFaultConfig ErrorQueue=""error""/>");
            }

            var registryErrorQueue = RegistryReader.Read("ErrorQueue");

            if (registryErrorQueue != null)
            {
                if (!string.IsNullOrWhiteSpace(registryErrorQueue))
                {
                    Logger.Debug("Error queue retrieved from registry settings.");
                    return(registryErrorQueue);
                }
                throw new Exception(
                          @"'ErrorQueue' read from registry but the value is empty.
Take one of the following actions:
- set the error queue at configuration time using 'EndpointConfiguration.SendFailedMessagesTo()'
- add a 'MessageForwardingInCaseOfFaultConfig' section to the app.config
- give 'HKEY_LOCAL_MACHINE\SOFTWARE\ParticularSoftware\ServiceBus\ErrorQueue' a valid value for the error queue");
            }

            throw new Exception(
                      @"Faults forwarding requires an error queue to be specified.
Take one of the following actions:
- set the error queue at configuration time using 'EndpointConfiguration.SendFailedMessagesTo()'
- add a 'MessageForwardingInCaseOfFaultConfig' section to the app.config
- configure a global error queue in the registry using the powershell command: Set-NServiceBusLocalMachineSettings -ErrorQueue {address of error queue}");
        }
示例#3
0
        /// <summary>
        /// Gets the explicitly configured error queue address if one is defined.
        /// The error queue can be configured in code using 'EndpointConfiguration.SendFailedMessagesTo()',
        /// via the 'Error' attribute of the 'MessageForwardingInCaseOfFaultConfig' configuration section,
        /// or using the 'HKEY_LOCAL_MACHINE\SOFTWARE\ParticularSoftware\ServiceBus\ErrorQueue' registry key.
        /// </summary>
        /// <param name="settings">The configuration settings of this endpoint.</param>
        /// <param name="errorQueue">The configured error queue.</param>
        /// <returns>True if an error queue has been explicitly configured.</returns>
        /// <exception cref="Exception">When the configuration for the endpoint is invalid.</exception>
        public static bool TryGetExplicitlyConfiguredErrorQueueAddress(this ReadOnlySettings settings, out string errorQueue)
        {
            Guard.AgainstNull(nameof(settings), settings);
            if (settings.HasExplicitValue(SettingsKey))
            {
                Logger.Debug("Error queue retrieved from code configuration via 'EndpointConfiguration.SendFailedMessagesTo()'.");
                errorQueue = settings.Get <string>(SettingsKey);
                return(true);
            }

            var section = settings.GetConfigSection <MessageForwardingInCaseOfFaultConfig>();

            if (section != null)
            {
                if (!string.IsNullOrWhiteSpace(section.ErrorQueue))
                {
                    Logger.Debug("Error queue retrieved from <MessageForwardingInCaseOfFaultConfig> element in config file.");
                    errorQueue = section.ErrorQueue;
                    return(true);
                }

                var message = "'MessageForwardingInCaseOfFaultConfig' configuration section exists, but 'ErrorQueue' value is empty. " +
                              $"Specify a value, or remove the configuration section so that the default error queue name, '{DefaultErrorQueueName}', will be used instead.";

                throw new Exception(message);
            }

            var registryErrorQueue = RegistryReader.Read("ErrorQueue");

            if (registryErrorQueue != null)
            {
                if (!string.IsNullOrWhiteSpace(registryErrorQueue))
                {
                    Logger.Debug("Error queue retrieved from registry settings.");
                    errorQueue = registryErrorQueue;
                    return(true);
                }

                var message = "'ErrorQueue' read from the registry, but the value is empty. Specify a value, or remove 'ErrorQueue' " +
                              $"from the registry so that the default error queue name, '{DefaultErrorQueueName}', will be used instead.";

                throw new Exception(message);
            }

            errorQueue = null;
            return(false);
        }
示例#4
0
        static string ReadAuditQueueNameFromRegistry()
        {
            var queue = RegistryReader.Read("AuditQueue");

            if (string.IsNullOrWhiteSpace(queue))
            {
                return(null);
            }
            // If Audit feature is enabled and the value not specified via config and instead specified in the registry:
            // Log a warning when running in the debugger to remind user to make sure the
            // production machine will need to have the required registry setting.
            if (Debugger.IsAttached)
            {
                Logger.Warn("Endpoint auditing is configured using the registry on this machine, see Particular Documentation for details on how to address this with your version of NServiceBus.");
            }
            return(queue);
        }
示例#5
0
        static string ReadAuditQueueNameFromRegistry()
        {
            var queue = RegistryReader.Read("AuditQueue");

            if (string.IsNullOrWhiteSpace(queue))
            {
                return(null);
            }
            // If Audit feature is enabled and the value not specified via config and instead specified in the registry:
            // Log a warning when running in the debugger to remind user to make sure the
            // production machine will need to have the required registry setting.
            if (Debugger.IsAttached)
            {
                Logger.Warn("Endpoint auditing is configured using the registry on this machine, please ensure that you either run Set-NServiceBusLocalMachineSettings cmdlet on the target deployment machine or specify the QueueName attribute in the AuditConfig section in your app.config file. To quickly add the AuditConfig section to your app.config, in Package Manager Console type: add-NServiceBusAuditConfig.");
            }
            return(queue);
        }