当前位置: 首页>>代码示例>>C#>>正文


C# BusConfiguration.DefineCriticalErrorAction方法代码示例

本文整理汇总了C#中BusConfiguration.DefineCriticalErrorAction方法的典型用法代码示例。如果您正苦于以下问题:C# BusConfiguration.DefineCriticalErrorAction方法的具体用法?C# BusConfiguration.DefineCriticalErrorAction怎么用?C# BusConfiguration.DefineCriticalErrorAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BusConfiguration的用法示例。


在下文中一共展示了BusConfiguration.DefineCriticalErrorAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnStart

    protected override void OnStart(string[] args)
    {
        try
        {
            var busConfiguration = new BusConfiguration();
            busConfiguration.EndpointName("SelfHostSample");
            busConfiguration.UseSerialization<JsonSerializer>();
            busConfiguration.DefineCriticalErrorAction(OnCriticalError);

            //TODO: this if is here to prevent you from accidentally deploy to production without considering important actions
            if (Environment.UserInteractive && Debugger.IsAttached)
            {
                //TODO: For production use, please select a durable persistence.
                //http://docs.particular.net/nservicebus/persistence/
                busConfiguration.UsePersistence<InMemoryPersistence>();

                //TODO: For production use, please script your installation.
                busConfiguration.EnableInstallers();
            }
            var startableBus = Bus.Create(busConfiguration);
            bus = startableBus.Start();
        }
        catch (Exception exception)
        {
            OnCriticalError("Failed to start the bus.", exception);
        }
    }
开发者ID:stephenpatten,项目名称:NServiceBus.Bootstrap.WindowsService,代码行数:27,代码来源:ProgramService.cs

示例2: OnStart

        protected override void OnStart(string[] args)
        {
            try
            {
                container = new Container(x => x.AddRegistry<DependencyRegistry>());
                var myDocumentStore = new DocumentStore { ConnectionStringName = "EpiFlowDB" };

                var busConfiguration = new BusConfiguration();
                busConfiguration.EndpointName("EpiFlow.Messages");
                busConfiguration.UseContainer<StructureMapBuilder>(c => c.ExistingContainer(container));
                busConfiguration.UseSerialization<JsonSerializer>();
                busConfiguration.UsePersistence<RavenDBPersistence>()
                    .UseDocumentStoreForSubscriptions(myDocumentStore)
                    .UseDocumentStoreForSagas(myDocumentStore)
                    .UseDocumentStoreForTimeouts(myDocumentStore);
                busConfiguration.UseTransport<RabbitMQTransport>();
                busConfiguration.DefineCriticalErrorAction(OnCriticalError);
                busConfiguration.Transactions().DisableDistributedTransactions();

                if (Environment.UserInteractive && Debugger.IsAttached)
                {
                    busConfiguration.EnableInstallers();
                }
                var startableBus = Bus.Create(busConfiguration);
                bus = startableBus.Start();
            }
            catch (Exception exception)
            {
                OnCriticalError("Failed to start the bus.", exception);
            }
        }
开发者ID:wettsten,项目名称:EpiFlow,代码行数:31,代码来源:ProgramService.cs

示例3: StartBus

        static void StartBus()
        {
            try
            {
                var myDocumentStore = new DocumentStore { ConnectionStringName = "EpiFlowDB" };

                var busConfiguration = new BusConfiguration();
                busConfiguration.EndpointName("EpiFlow.Messages");
                busConfiguration.UseSerialization<JsonSerializer>();
                busConfiguration.UsePersistence<RavenDBPersistence>()
                    .UseDocumentStoreForSubscriptions(myDocumentStore)
                    .UseDocumentStoreForSagas(myDocumentStore)
                    .UseDocumentStoreForTimeouts(myDocumentStore);
                busConfiguration.UseTransport<RabbitMQTransport>();
                busConfiguration.DefineCriticalErrorAction(OnCriticalError);
                busConfiguration.Transactions().DisableDistributedTransactions();

                if (Environment.UserInteractive && Debugger.IsAttached)
                {
                    busConfiguration.EnableInstallers();
                }
                _bus = Bus.CreateSendOnly(busConfiguration);
            }
            catch (Exception exception)
            {
                OnCriticalError("Failed to start the bus.", exception);
            }
        }
开发者ID:wettsten,项目名称:EpiFlow,代码行数:28,代码来源:Program.cs

示例4: CriticalErrors

        CriticalErrors(BusConfiguration busConfiguration)
        {
            #region DefiningCustomHostErrorHandlingAction

            busConfiguration.DefineCriticalErrorAction(OnCriticalError);

            #endregion
        }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:8,代码来源:CriticalErrors.cs

示例5: CriticalErrors

        CriticalErrors()
        {
            #region DefiningCustomHostErrorHandlingAction

            var busConfiguration = new BusConfiguration();
            busConfiguration.DefineCriticalErrorAction(OnCriticalError);

            #endregion
        }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:9,代码来源:CriticalErrors.cs

示例6: Simple

    public void Simple()
    {
        #region DefineCriticalErrorActionV5

        var configuration = new BusConfiguration();

        configuration.DefineCriticalErrorAction((s, exception) =>
            {
                // custom exception handling
            });


        #endregion
    }
开发者ID:KrzysztofKielce,项目名称:docs.particular.net,代码行数:14,代码来源:DefineCriticalErrorAction.cs

示例7: CriticalError

        void CriticalError(BusConfiguration busConfiguration)
        {
            // ReSharper disable RedundantDelegateCreation

            #region 5to6CriticalError

            busConfiguration.DefineCriticalErrorAction(
                new Action<string, Exception>((error, exception) =>
                {
                    // place you custom handling here
                }));

            #endregion

            // ReSharper restore RedundantDelegateCreation
        }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:16,代码来源:Upgrade.cs

示例8: CriticalError

 public void CriticalError()
 {
     // ReSharper disable RedundantDelegateCreation
     // ReSharper disable ConvertToLambdaExpression
     #region 5to6CriticalError
     var busConfiguration = new BusConfiguration();
     busConfiguration.DefineCriticalErrorAction(
         new Func<ICriticalErrorContext,Task>(context =>
         {
             // place you custom handling here 
             return Task.FromResult(0);
         }));
     #endregion
     // ReSharper restore RedundantDelegateCreation
     // ReSharper restore ConvertToLambdaExpression
 }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:16,代码来源:Upgrade.cs

示例9: Customize

        public void Customize(BusConfiguration configuration)
        {
            configuration.UseTransport<AzureServiceBusTransport>();
            configuration.UsePersistence<AzureStoragePersistence>();

            configuration.Conventions()
                .DefiningCommandsAs(t => t.Namespace != null && (t.Namespace.StartsWith("Commands") || t.Namespace.Contains("Commands")))
                .DefiningEventsAs(t => t.Namespace != null && (t.Namespace.EndsWith("Events") || t.Namespace.EndsWith("Notifications")));

            // Configuring how NServicebus handles critical errors - pre version 6.2.2
            configuration.DefineCriticalErrorAction((message, exception) =>
            {
                var errorMessage = string.Format("We got a critical exception: '{0}'\r\n{1}", message, exception);
                var fatalMessage = string.Format("The following critical error was encountered by NServiceBus:\n{0}\nNServiceBus is shutting down.", errorMessage);
                Environment.FailFast(fatalMessage, exception);
            });
        }
开发者ID:jpv001,项目名称:DistributedMessagingExample,代码行数:17,代码来源:Endpoint.cs

示例10: DefineCriticalErrorAction

    public void DefineCriticalErrorAction()
    {

        #region DefineCriticalErrorActionV5

        var configuration = new BusConfiguration();

        // Configuring how NServicebus handles critical errors
        configuration.DefineCriticalErrorAction((message, exception) =>
        {
            var output = string.Format("We got a critical exception: '{0}'\r\n{1}", message, exception);
            Debug.WriteLine(output);
            // Perhaps end the process??
        });

        #endregion
    }
开发者ID:fafachd,项目名称:docs.particular.net,代码行数:17,代码来源:CriticalError.cs

示例11: CriticalErrorConfigAzure

        CriticalErrorConfigAzure(BusConfiguration busConfiguration, ILog log)
        {
            #region DefineCriticalErrorActionForAzureHost

            // Configuring how NServiceBus handles critical errors
            busConfiguration.DefineCriticalErrorAction((message, exception) =>
            {
                var output = $"Critical exception: '{message}'";
                log.Error(output, exception);
                if (Environment.UserInteractive)
                {
                    Thread.Sleep(10000); // so that user can see on their screen the problem
                }

                var fatalMessage = $"The following critical error was encountered by NServiceBus:\n{message}\nNServiceBus is shutting down.";
                Environment.FailFast(fatalMessage, exception);
            });

            #endregion
        }
开发者ID:chriscatilo,项目名称:docs.particular.net,代码行数:20,代码来源:CriticalErrorConfigAzure.cs

示例12: DefineCriticalErrorActionForAzureHost

        public void DefineCriticalErrorActionForAzureHost()
        {
            BusConfiguration busConfiguration = new BusConfiguration();

            #region DefineCriticalErrorActionForAzureHost

            // Configuring how NServicebus handles critical errors
            busConfiguration.DefineCriticalErrorAction((message, exception) =>
            {
                string errorMessage = string.Format("We got a critical exception: '{0}'\r\n{1}", message, exception);

                if (Environment.UserInteractive)
                {
                    Thread.Sleep(10000); // so that user can see on their screen the problem
                }

                string fatalMessage = string.Format("The following critical error was encountered by NServiceBus:\n{0}\nNServiceBus is shutting down.", errorMessage);
                Environment.FailFast(fatalMessage, exception);
            });

            #endregion
        }
开发者ID:RichieYang,项目名称:docs.particular.net,代码行数:22,代码来源:CriticalError.cs

示例13: DefineCriticalErrorActionForAzureHost

        public void DefineCriticalErrorActionForAzureHost()
        {
            BusConfiguration busConfiguration = new BusConfiguration();

            #region DefineCriticalErrorActionForAzureHost

            // Configuring how NServicebus handles critical errors
            busConfiguration.DefineCriticalErrorAction(context =>
            {
                string errorMessage = $"We got a critical exception: '{context.Error}'\r\n{context.Exception}";

                if (Environment.UserInteractive)
                {
                    Thread.Sleep(10000); // so that user can see on their screen the problem
                }

                string fatalMessage = $"The following critical error was encountered by NServiceBus:\n{errorMessage}\nNServiceBus is shutting down.";
                Environment.FailFast(fatalMessage, context.Exception);
                return Task.FromResult(0);
            });

            #endregion
        }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:23,代码来源:CriticalError.cs

示例14: OnStart

    protected override void OnStart(string[] args)
    {
        #region logging
        PatternLayout layout = new PatternLayout
        {
            ConversionPattern = "%d %-5p %c - %m%n"
        };
        layout.ActivateOptions();
        ConsoleAppender appender = new ConsoleAppender
        {
            Layout = layout,
            Threshold = Level.Info
        };
        appender.ActivateOptions();

        BasicConfigurator.Configure(appender);

        LogManager.Use<Log4NetFactory>();
        #endregion

        #region create-config
        BusConfiguration busConfiguration = new BusConfiguration();
        #endregion

        #region endpoint-name
        busConfiguration.EndpointName("Samples.FirstEndpoint");
        #endregion

        #region container
        ContainerBuilder builder = new ContainerBuilder();
        //configure your custom services
        //builder.RegisterInstance(new MyService());
        IContainer container = builder.Build();
        busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));
        #endregion

        #region serialization
        busConfiguration.UseSerialization<JsonSerializer>();
        #endregion

        #region transport
        busConfiguration.UseTransport<MsmqTransport>();
        #endregion

        #region sagas 
        //Not required since Sagas are enabled by default in Version 5
        #endregion

        #region persistence
        busConfiguration.UsePersistence<InMemoryPersistence, StorageType.Sagas>();
        busConfiguration.UsePersistence<InMemoryPersistence, StorageType.Subscriptions>();
        busConfiguration.UsePersistence<InMemoryPersistence, StorageType.Timeouts>();
        #endregion

        #region critical-errors
        busConfiguration.DefineCriticalErrorAction((errorMessage, exception) =>
        {
            // Log the critical error
            logger.Fatal(string.Format("CRITICAL: {0}", errorMessage), exception);

            // Kill the process on a critical error
            string output = string.Format("The following critical error was encountered by NServiceBus:\n{0}\nNServiceBus is shutting down.", errorMessage);
            Environment.FailFast(output, exception);
        });
        #endregion

        #region start-bus
        busConfiguration.EnableInstallers();
        bus = Bus.Create(busConfiguration).Start();
        #endregion
    }
开发者ID:RichieYang,项目名称:docs.particular.net,代码行数:71,代码来源:ProgramService.cs

示例15: PerformConfiguration

        void PerformConfiguration(Action<BusConfiguration> moreConfiguration = null)
        {
            var loggingConfigurers = profileManager.GetLoggingConfigurer();
            foreach (var loggingConfigurer in loggingConfigurers)
            {
                loggingConfigurer.Configure(specifier);
            }

            var configuration = new BusConfiguration();

            configuration.EndpointName(endpointNameToUse);
            configuration.EndpointVersion(endpointVersionToUse);
            configuration.AssembliesToScan(assembliesToScan);
            configuration.DefineCriticalErrorAction(OnCriticalError);

            if (moreConfiguration != null)
            {
                moreConfiguration(configuration);
            }

            specifier.Customize(configuration);
            RoleManager.TweakConfigurationBuilder(specifier, configuration);
            profileManager.ActivateProfileHandlers(configuration);

            bus = (UnicastBus) Bus.Create(configuration);
        }
开发者ID:ogdenmd,项目名称:NServiceBus,代码行数:26,代码来源:GenericHost.cs


注:本文中的BusConfiguration.DefineCriticalErrorAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。