public static void StartNServiceBus(this UpdateableServiceProvider serviceProvider,
                                            IConfiguration configuration, bool configurationIsLocalOrDev)
        {
            var endpointConfiguration = new EndpointConfiguration("SFA.DAS.Reservations.Api")
                                        .UseInstallers()
                                        .UseMessageConventions()
                                        .UseNewtonsoftJsonSerializer()
                                        .UseOutbox(true)
                                        .UseServicesBuilder(serviceProvider)
                                        .UseSqlServerPersistence(() => new SqlConnection(configuration["Reservations:ConnectionString"]))
                                        .UseUnitOfWork();

            if (configurationIsLocalOrDev)
            {
                endpointConfiguration.UseLearningTransport();
            }
            else
            {
                endpointConfiguration.UseAzureServiceBusTransport(
                    configuration["Reservations:NServiceBusConnectionString"], r => { });
            }

            if (!string.IsNullOrEmpty(configuration["Reservations:NServiceBusLicense"]))
            {
                endpointConfiguration.License(configuration["Reservations:NServiceBusLicense"]);
            }


            var endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            serviceProvider.AddSingleton(p => endpoint)
            .AddSingleton <IMessageSession>(p => p.GetService <IEndpointInstance>())
            .AddHostedService <NServiceBusHostedService>();
        }
Ejemplo n.º 2
0
        public static async Task <UpdateableServiceProvider> StartNServiceBus(this UpdateableServiceProvider serviceProvider, IConfiguration configuration)
        {
            var connectionFactory = serviceProvider.GetService <IConnectionFactory>();

            var endpointConfiguration = new EndpointConfiguration("SFA.DAS.ApprenticeCommitments.Api")
                                        .UseMessageConventions()
                                        .UseNewtonsoftJsonSerializer()
                                        .UseOutbox(true)
                                        .UseServicesBuilder(serviceProvider)
                                        .UseSqlServerPersistence(() => connectionFactory.CreateConnection(configuration["ApplicationSettings:DbConnectionString"]))
                                        .UseUnitOfWork();

            if (UseLearningTransport(configuration))
            {
                endpointConfiguration.UseTransport <LearningTransport>();
            }
            else
            {
                endpointConfiguration.UseAzureServiceBusTransport(configuration["ApplicationSettings:NServiceBusConnectionString"]);
            }

            if (!string.IsNullOrEmpty(configuration["ApplicationSettings:NServiceBusLicense"]))
            {
                endpointConfiguration.License(configuration["ApplicationSettings:NServiceBusLicense"]);
            }

            var endpoint = await Endpoint.Start(endpointConfiguration);

            serviceProvider.AddSingleton(p => endpoint)
            .AddSingleton <IMessageSession>(p => p.GetService <IEndpointInstance>())
            .AddHostedService <NServiceBusHostedService>();

            return(serviceProvider);
        }
Ejemplo n.º 3
0
        public static async Task <UpdateableServiceProvider> StartNServiceBus(
            this UpdateableServiceProvider serviceProvider,
            IConfiguration configuration)
        {
            var endpointName = configuration["ApplicationSettings:NServiceBusEndpointName"];

            if (string.IsNullOrEmpty(endpointName))
            {
                endpointName = "SFA.DAS.EmployerIncentives.Functions.DomainMessageHandlers";
            }

            var endpointConfiguration = new EndpointConfiguration(endpointName)
                                        .UseMessageConventions()
                                        .UseNewtonsoftJsonSerializer()
                                        .UseOutbox(true)
                                        .UseServicesBuilder(serviceProvider)
                                        .UseSqlServerPersistence(() => new SqlConnection(configuration["ApplicationSettings:DbConnectionString"]))
                                        .UseUnitOfWork();

            if (configuration["ApplicationSettings:NServiceBusConnectionString"].Equals("UseLearningEndpoint=true", StringComparison.CurrentCultureIgnoreCase))
            {
                endpointConfiguration
                .UseTransport <LearningTransport>()
                .StorageDirectory(configuration.GetValue("ApplicationSettings:UseLearningEndpointStorageDirectory",
                                                         Path.Combine(
                                                             Directory.GetCurrentDirectory().Substring(0, Directory.GetCurrentDirectory().IndexOf("src")),
                                                             @"src\SFA.DAS.EmployerIncentives.Functions.TestConsole\.learningtransport")));
                endpointConfiguration.UseLearningTransport(s => s.AddRouting());
            }
            else
            {
                endpointConfiguration
                .UseAzureServiceBusTransport(configuration["ApplicationSettings:NServiceBusConnectionString"], r => r.AddRouting());
            }

            if (!string.IsNullOrEmpty(configuration["ApplicationSettings:NServiceBusLicense"]))
            {
                endpointConfiguration.License(configuration["ApplicationSettings:NServiceBusLicense"]);
            }

            var endpoint = await Endpoint.Start(endpointConfiguration);

            serviceProvider.AddSingleton(p => endpoint)
            .AddSingleton <IMessageSession>(p => p.GetService <IEndpointInstance>())
            .AddHostedService <NServiceBusHostedService>();

            return(serviceProvider);
        }
        public static void StartNServiceBus(this UpdateableServiceProvider serviceProvider, IConfiguration configuration)
        {
            var endpointName          = "SFA.DAS.UnitOfWork.Sample.Web";
            var endpointConfiguration = new EndpointConfiguration(endpointName)
                                        .UseLearningTransport()
                                        .UseErrorQueue($"{endpointName}-errors")
                                        .UseInstallers()
                                        .UseMessageConventions()
                                        .UseNewtonsoftJsonSerializer()
                                        .UseOutbox()
                                        .UseServicesBuilder(serviceProvider)
                                        .UseSqlServerPersistence(() => new SqlConnection(configuration.GetConnectionString("SampleDb")));

            var endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            serviceProvider.AddSingleton(p => endpoint)
            .AddSingleton <IMessageSession>(p => p.GetService <IEndpointInstance>())
            .AddHostedService <NServiceBusHostedService>();
        }
Ejemplo n.º 5
0
        public static async Task <UpdateableServiceProvider> StartNServiceBus(
            this UpdateableServiceProvider serviceProvider,
            IConfiguration configuration,
            string endpointName)
        {
            var config = configuration
                         .GetSection("NServiceBusConfiguration")
                         .Get <NServiceBusConfiguration>();

            var endpointConfiguration = new EndpointConfiguration(endpointName)
                                        .UseErrorQueue($"{endpointName}-errors")
                                        .UseInstallers()
                                        .UseMessageConventions()
                                        .UseNewtonsoftJsonSerializer()
                                        .UseNLogFactory();

            if (!string.IsNullOrEmpty(config.NServiceBusLicense))
            {
                endpointConfiguration.UseLicense(config.NServiceBusLicense);
            }

            endpointConfiguration.SendOnly();

            if (config.NServiceBusConnectionString.Equals("UseLearningEndpoint=true", StringComparison.CurrentCultureIgnoreCase))
            {
                endpointConfiguration.UseLearningTransport(s => s.AddRouting());
            }
            else
            {
                endpointConfiguration.UseAzureServiceBusTransport(config.NServiceBusConnectionString, s => s.AddRouting());
            }

            var endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            serviceProvider.AddSingleton(p => endpoint)
            .AddSingleton <IMessageSession>(p => p.GetService <IEndpointInstance>())
            .AddHostedService <NServiceBusHostedService>();

            return(serviceProvider);
        }