Beispiel #1
0
        public static void AddNsb(this IServiceCollection services)
        {
            var licensePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NSB_License.xml");

            var config = new EndpointConfiguration("SignalRTest");

            if (File.Exists(licensePath))
            {
                config.LicensePath(licensePath);
            }

            config.UseTransport <LearningTransport>();

            config.RegisterComponents(
                configComp =>
            {
                configComp.ConfigureComponent(() =>
                                              GetHubContext(services),
                                              DependencyLifecycle.InstancePerCall);
            });

            var session = Endpoint.Start(config).Result;

            services.AddSingleton <IMessageSession>(session);
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            var endpointConfiguration = new NServiceBus.EndpointConfiguration("demo");
            var transport             = endpointConfiguration.UseTransport <RabbitMQTransport>();

            transport.ConnectionString(@"host=localhost;username=guest;password=guest");
            transport.UseConventionalRoutingTopology();
            transport.Routing().RouteToEndpoint(typeof(HelloWorldMessage), "consumer1");
            endpointConfiguration.SendOnly();
            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.EnableInstallers();
            var endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            services.AddSingleton <IMessageSession>(endpointInstance);
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info {
                    Title = "My API", Version = "v1"
                });
            });
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }
Beispiel #3
0
        //create messaging endpoint
        private static async Task Main()
        {
            Console.Title = "ClientUI";

            //EndpointConfiguration class defintes all settings which determines how endpoint operates
            //string ClientUI is endpoint name
            var endpointConfiguration = new EndpointConfiguration("ClientUI");

            //            //transport is a setting which NServiceBus uses to send and receives messages
            //            var transport = endpointConfiguration.UseTransport<LearningTransport>();

            //MSMQ does not support natively Publish/Subscribe
            var transport = endpointConfiguration.UseTransport <MsmqTransport>();

            //message subscription info stored in memory instead
            endpointConfiguration.UsePersistence <InMemoryPersistence>();

            //error queue specified
            endpointConfiguration.SendFailedMessagesTo("error");

            //creates message queues required by endpoints
            endpointConfiguration.EnableInstallers();

            //establises commands of type PlaceOrder should be sent to the Sales endpoint
            var routing = transport.Routing();

            routing.RouteToEndpoint(typeof(PlaceOrder), "Sales");

            endpointConfiguration.UseSerialization <JsonSerializer>();

            //starts endpoint
            var endpointInstance = await Endpoint.Start(endpointConfiguration)
                                   .ConfigureAwait(false);

            await RunLoop(endpointInstance)
            .ConfigureAwait(false);

            //endpoint runs until user presses enter and then stops
            await endpointInstance.Stop()
            .ConfigureAwait(false);
        }
Beispiel #4
0
        public async Task Start()
        {
            try
            {
                var endpointConfiguration = new NServiceBus.EndpointConfiguration(EndpointName);

                //These 2 settings happen for all endpoints
                endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);
                endpointConfiguration.UseContainer <StructureMapBuilder>(x => x.ExistingContainer(container));

                foreach (var configure in configs)
                {
                    configure.Configure(endpointConfiguration);
                }

                endpoint = await Endpoint.Start(endpointConfiguration);
            }
            catch (Exception ex)
            {
                FailFast("Failed to start.", ex);
            }
        }
Beispiel #5
0
    public static async Task <IEndpointInstance> Configure(string endpointName)
    {
        var endpointConfiguration = new NServiceBus.EndpointConfiguration(endpointName);

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.EnableInstallers();

        var transport = endpointConfiguration.UseTransport <AzureServiceBusTransport>();

        var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString");

        if (string.IsNullOrWhiteSpace(connectionString))
        {
            throw new Exception("Could not read the 'AzureServiceBus_ConnectionString' environment variable. Check the sample prerequisites.");
        }

        transport.ConnectionString(connectionString);

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        return(endpointInstance);
    }
Beispiel #6
0
 /// <summary>
 /// If queues configured do not exist, will cause them not to be created on startup.
 /// </summary>
 /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
 public static void DoNotCreateQueues(this EndpointConfiguration config)
 {
     Guard.AgainstNull(nameof(config), config);
     config.Settings.Set("Transport.CreateQueues", false);
 }
        /// <summary>
        /// Creates a new startable endpoint based on the provided configuration.
        /// </summary>
        /// <param name="configuration">Configuration.</param>
        public static Task <IStartableEndpoint> Create(EndpointConfiguration configuration)
        {
            Guard.AgainstNull(nameof(configuration), configuration);

            return(HostCreator.CreateWithInternallyManagedContainer(configuration));
        }
 /// <summary>
 /// A critical error is raised when timeout retrieval fails.
 /// By default we wait for 2 seconds for the storage to come back.
 /// This method allows to change the default and extend the wait time.
 /// </summary>
 /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
 /// <param name="timeToWait">Time to wait before raising a critical error.</param>
 public static void TimeToWaitBeforeTriggeringCriticalErrorOnTimeoutOutages(this EndpointConfiguration config, TimeSpan timeToWait)
 {
     Guard.AgainstNull(nameof(config), config);
     Guard.AgainstNegative(nameof(timeToWait), timeToWait);
     config.Settings.Set("TimeToWaitBeforeTriggeringCriticalErrorForTimeoutPersisterReceiver", timeToWait);
 }
Beispiel #9
0
 public static void EnableCriticalTimePerformanceCounter(this EndpointConfiguration config)
 {
     Guard.AgainstNull(nameof(config), config);
     config.EnableFeature <CriticalTimeMonitoring>();
 }
 public static void ForwardReceivedMessagesTo(this EndpointConfiguration config, string address)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
 public static void DefineEndpointName(this EndpointConfiguration configuration, string endpointName)
 {
     throw new NotImplementedException();
 }
Beispiel #12
0
 internal UnitOfWorkSettings(EndpointConfiguration config)
 {
     this.config = config;
 }
Beispiel #13
0
 internal HostInfoSettings(EndpointConfiguration config)
 {
     Guard.AgainstNull(nameof(config), config);
     this.config = config;
 }
Beispiel #14
0
 public static EndpointConfiguration SetFrequencyToRunDeduplicationDataCleanup(this EndpointConfiguration configuration, TimeSpan frequencyToRunDeduplicationDataCleanup)
 {
     configuration.GetSettings().SetFrequencyToRunDeduplicationDataCleanup(frequencyToRunDeduplicationDataCleanup);
     return(configuration);
 }
Beispiel #15
0
 public static EndpointConfiguration SetTimeToKeepDeduplicationData(this EndpointConfiguration configuration, TimeSpan timeToKeepDeduplicationData)
 {
     configuration.GetSettings().SetTimeToKeepDeduplicationData(timeToKeepDeduplicationData);
     return(configuration);
 }
Beispiel #16
0
        public static ExternallyManagedContainerHost CreateWithExternallyManagedContainer(EndpointConfiguration endpointConfiguration, IConfigureComponents externalContainer)
        {
            var settings = endpointConfiguration.Settings;

            CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings);

            var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings);

            endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes);

            var hostingSettings = settings.Get <HostingComponent.Settings>();

            var hostingConfiguration = HostingComponent.PrepareConfiguration(hostingSettings, assemblyScanningComponent, externalContainer);

            if (hostingSettings.CustomObjectBuilder != null)
            {
                throw new InvalidOperationException("An internally managed container has already been configured using 'EndpointConfiguration.UseContainer'. It is not possible to use both an internally managed container and an externally managed container.");
            }

            hostingConfiguration.AddStartupDiagnosticsSection("Container", new
            {
                Type = "external"
            });

            var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration);

            var externallyManagedContainerHost = new ExternallyManagedContainerHost(endpointCreator, hostingConfiguration);

            //for backwards compatibility we need to make the IBuilder available in the container
            externalContainer.ConfigureComponent(_ => externallyManagedContainerHost.Builder.Value, DependencyLifecycle.SingleInstance);

            return(externallyManagedContainerHost);
        }
Beispiel #17
0
        public static async Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration)
        {
            var settings = endpointConfiguration.Settings;

            CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings);

            var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings);

            endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes);

            var hostingSetting    = settings.Get <HostingComponent.Settings>();
            var useDefaultBuilder = hostingSetting.CustomObjectBuilder == null;
            var container         = useDefaultBuilder ? new LightInjectObjectBuilder() : hostingSetting.CustomObjectBuilder;

            var commonObjectBuilder = new CommonObjectBuilder(container);

            IConfigureComponents internalContainer = commonObjectBuilder;
            IBuilder             internalBuilder   = commonObjectBuilder;

            //for backwards compatibility we need to make the IBuilder available in the container
            internalContainer.ConfigureComponent(_ => internalBuilder, DependencyLifecycle.SingleInstance);

            var hostingConfiguration = HostingComponent.PrepareConfiguration(settings.Get <HostingComponent.Settings>(), assemblyScanningComponent, internalContainer);

            if (useDefaultBuilder)
            {
                hostingConfiguration.AddStartupDiagnosticsSection("Container", new
                {
                    Type = "internal"
                });
            }
            else
            {
                var containerType = internalContainer.GetType();

                hostingConfiguration.AddStartupDiagnosticsSection("Container", new
                {
                    Type    = containerType.FullName,
                    Version = FileVersionRetriever.GetFileVersion(containerType)
                });
            }

            var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration);

            var hostingComponent = HostingComponent.Initialize(hostingConfiguration);

            var startableEndpoint = endpointCreator.CreateStartableEndpoint(internalBuilder, hostingComponent);

            hostingComponent.RegisterBuilder(internalBuilder, true);

            await hostingComponent.RunInstallers().ConfigureAwait(false);

            return(new InternallyManagedContainerHost(startableEndpoint, hostingComponent));
        }
Beispiel #18
0
        public static StartableEndpointWithExternallyManagedContainer CreateWithExternallyManagedContainer(EndpointConfiguration endpointConfiguration, IConfigureComponents configureComponents)
        {
            FinalizeConfiguration(endpointConfiguration);

            endpointConfiguration.ContainerComponent.InitializeWithExternallyManagedContainer(configureComponents);

            var creator = new EndpointCreator(endpointConfiguration.Settings, endpointConfiguration.ContainerComponent);

            creator.Initialize();

            return(new StartableEndpointWithExternallyManagedContainer(creator));
        }
Beispiel #19
0
 public static void RunWhenEndpointStartsAndStops(this EndpointConfiguration configuration, IWantToRunWhenEndpointStartsAndStops startableAndStoppable)
 {
     throw new NotImplementedException();
 }
 internal GatewaySettings(EndpointConfiguration config)
 {
     this.config = config;
 }