Esempio n. 1
0
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;

            logger.Debug("Constructing bus...");

            configuration.AssertConfigurationIsValid();

            var container = new PoorMansIoC();

            container.RegisterPropertiesFromConfigurationObject(configuration);

            logger.Debug("Creating message pumps...");
            var messagePumpsManager = new MessagePumpsManager(
                container.Resolve <ResponseMessagePumpFactory>().Create(),
                container.Resolve <RequestMessagePumpsFactory>().CreateAll(),
                container.Resolve <CommandMessagePumpsFactory>().CreateAll(),
                container.Resolve <MulticastRequestMessagePumpsFactory>().CreateAll(),
                container.Resolve <MulticastEventMessagePumpsFactory>().CreateAll(),
                container.Resolve <CompetingEventMessagePumpsFactory>().CreateAll());

            logger.Debug("Message pumps are all created.");

            var bus = container.ResolveWithOverrides <Bus>(messagePumpsManager);

            container.Resolve <PropertyInjector>().Bus = bus;

            bus.Starting += (s, e) =>
            {
                Task.Run(async() =>
                {
                    try
                    {
                        await container.Resolve <INimbusTransport>().TestConnection();
                        await CleanNamespace(container, logger);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Failed to establish connection to underlying transport: {Message}", ex.Message);
                        throw;
                    }
                }).Wait();
            };

            bus.Disposing += (s, e) =>
            {
                Task.Run(async() =>
                {
                    await CleanNamespace(container, logger);
                    container.Dispose();
                }).Wait();
            };

            logger.Info("Bus built. Job done!");

            return(bus);
        }
Esempio n. 2
0
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;
            logger.Debug("Constructing bus...");

            configuration.AssertConfigurationIsValid();

            var container = new PoorMansIoC();
            container.RegisterPropertiesFromConfigurationObject(configuration);

            logger.Debug("Creating message pumps...");
            var messagePumpsManager = new MessagePumpsManager(
                container.Resolve<ResponseMessagePumpFactory>().Create(),
                container.Resolve<RequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<CommandMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(),
                container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll());

            logger.Debug("Message pumps are all created.");

            var bus = container.ResolveWithOverrides<Bus>(messagePumpsManager);
            container.Resolve<PropertyInjector>().Bus = bus;

            bus.Starting += (s, e) =>
                            {
                                Task.Run(async () =>
                                               {
                                                   try
                                                   {
                                                       await container.Resolve<INimbusTransport>().TestConnection();
                                                       await CleanNamespace(container, logger);
                                                   }
                                                   catch (Exception ex)
                                                   {
                                                       logger.Error(ex, "Failed to establish connection to underlying transport: {Message}", ex.Message);
                                                       throw;
                                                   }
                                               }).Wait();
                            };

            bus.Disposing += (s, e) =>
                             {
                                 Task.Run(async () =>
                                                {
                                                    await CleanNamespace(container, logger);
                                                    container.Dispose();
                                                }).Wait();
                             };

            logger.Info("Bus built. Job done!");

            return bus;
        }
Esempio n. 3
0
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;

            logger.Debug("Constructing bus...");

            configuration.AssertConfigurationIsValid();

            var container = new PoorMansIoC();

            container.RegisterPropertiesFromConfigurationObject(configuration);

            logger.Debug("Creating message pumps...");
            var messagePumpsManager = new MessagePumpsManager(
                container.Resolve <ResponseMessagePumpFactory>().Create(),
                container.Resolve <RequestMessagePumpsFactory>().CreateAll(),
                container.Resolve <CommandMessagePumpsFactory>().CreateAll(),
                container.Resolve <MulticastRequestMessagePumpsFactory>().CreateAll(),
                container.Resolve <MulticastEventMessagePumpsFactory>().CreateAll(),
                container.Resolve <CompetingEventMessagePumpsFactory>().CreateAll());

            logger.Debug("Message pumps are all created.");

            var bus = container.ResolveWithOverrides <Bus>(messagePumpsManager);

            container.Resolve <PropertyInjector>().Bus = bus;

            bus.Starting += delegate
            {
                container.Resolve <INimbusTransport>().TestConnection().Wait();

                var removeAllExistingElements = container.Resolve <RemoveAllExistingNamespaceElementsSetting>();
                if (removeAllExistingElements)
                {
                    logger.Debug("Removing all existing namespace elements. IMPORTANT: This should only be done in your regression test suites.");
                    var cleanser = container.Resolve <INamespaceCleanser>();
                    cleanser.RemoveAllExistingNamespaceElements().Wait();
                }
            };
            bus.Disposing += delegate { container.Dispose(); };

            logger.Info("Bus built. Job done!");

            return(bus);
        }
Esempio n. 4
0
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;
            logger.Debug("Constructing bus...");

            configuration.AssertConfigurationIsValid();

            var container = new PoorMansIoC();
            container.RegisterPropertiesFromConfigurationObject(configuration);

            logger.Debug("Creating message pumps...");
            var messagePumpsManager = new MessagePumpsManager(
                container.Resolve<ResponseMessagePumpFactory>().Create(),
                container.Resolve<RequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<CommandMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(),
                container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll());

            logger.Debug("Message pumps are all created.");

            var bus = container.ResolveWithOverrides<Bus>(messagePumpsManager);
            container.Resolve<PropertyInjector>().Bus = bus;

            bus.Starting += delegate
                            {
                                container.Resolve<INimbusTransport>().TestConnection().Wait();

                                var removeAllExistingElements = container.Resolve<RemoveAllExistingNamespaceElementsSetting>();
                                if (removeAllExistingElements)
                                {
                                    logger.Debug("Removing all existing namespace elements. IMPORTANT: This should only be done in your regression test suites.");
                                    var cleanser = container.Resolve<INamespaceCleanser>();
                                    cleanser.RemoveAllExistingNamespaceElements().Wait();
                                }
                            };
            bus.Disposing += delegate { container.Dispose(); };

            logger.Info("Bus built. Job done!");

            return bus;
        }
Esempio n. 5
0
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;
            logger.Debug("Constructing bus...");

            var container = new PoorMansIoC();

            RegisterPropertiesFromConfigurationObject(container, configuration);
            RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration);
            RegisterPropertiesFromConfigurationObject(container, configuration.Debugging);

            var namespaceManagerRoundRobin = new RoundRobin<NamespaceManager>(
                container.Resolve<ServerConnectionCountSetting>(),
                () =>
                {
                    var namespaceManager = NamespaceManager.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>());
                    namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(120);
                    return namespaceManager;
                },
                nsm => false,
                nsm => { });

            container.Register<Func<NamespaceManager>>(c => namespaceManagerRoundRobin.GetNext);

            var messagingFactoryRoundRobin = new RoundRobin<MessagingFactory>(
                container.Resolve<ServerConnectionCountSetting>(),
                () =>
                {
                    var messagingFactory = MessagingFactory.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>());
                    messagingFactory.PrefetchCount = container.Resolve<ConcurrentHandlerLimitSetting>();
                    return messagingFactory;
                },
                mf => mf.IsBorked(),
                mf => { });

            container.Register<Func<MessagingFactory>>(c => messagingFactoryRoundRobin.GetNext);

            if (configuration.Debugging.RemoveAllExistingNamespaceElements)
            {
                var namespaceCleanser = container.Resolve<NamespaceCleanser>();
                namespaceCleanser.RemoveAllExistingNamespaceElements().Wait();
            }

            logger.Debug("Creating message pumps...");

            var messagePumps = new MessagePumpsManager(
                container.Resolve<ResponseMessagePumpFactory>().Create(),
                container.Resolve<RequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<CommandMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(),
                container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll(),
                container.Resolve<INimbusTaskFactory>());

            logger.Debug("Message pumps are all created.");

            var bus = new Bus(container.Resolve<ILogger>(),
                              container.Resolve<ICommandSender>(),
                              container.Resolve<IRequestSender>(),
                              container.Resolve<IMulticastRequestSender>(),
                              container.Resolve<IEventSender>(),
                              messagePumps,
                              container.Resolve<DeadLetterQueues>(),
                              container.Resolve<INimbusTaskFactory>(),
                              container.Resolve<IHeartbeat>());

            bus.Starting += delegate
                            {
                                container.Resolve<AzureQueueManager>().WarmUp();
                                container.Resolve<PropertyInjector>().Bus = bus;
                            };
            bus.Disposing += delegate { container.Dispose(); };

            logger.Info("Bus built. Job done!");

            return bus;
        }
Esempio n. 6
0
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;

            logger.Debug("Constructing bus...");

            var container = new PoorMansIoC();

            RegisterPropertiesFromConfigurationObject(container, configuration);
            RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration);
            RegisterPropertiesFromConfigurationObject(container, configuration.Debugging);

            var namespaceManagerRoundRobin = new RoundRobin <NamespaceManager>(
                container.Resolve <ServerConnectionCountSetting>(),
                () =>
            {
                var namespaceManager = NamespaceManager.CreateFromConnectionString(container.Resolve <ConnectionStringSetting>());
                namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(120);
                return(namespaceManager);
            },
                nsm => false,
                nsm => { });

            container.Register <Func <NamespaceManager> >(c => namespaceManagerRoundRobin.GetNext);

            var messagingFactoryRoundRobin = new RoundRobin <MessagingFactory>(
                container.Resolve <ServerConnectionCountSetting>(),
                () =>
            {
                var messagingFactory           = MessagingFactory.CreateFromConnectionString(container.Resolve <ConnectionStringSetting>());
                messagingFactory.PrefetchCount = container.Resolve <ConcurrentHandlerLimitSetting>();
                return(messagingFactory);
            },
                mf => mf.IsBorked(),
                mf => { });

            container.Register <Func <MessagingFactory> >(c => messagingFactoryRoundRobin.GetNext);

            if (configuration.Debugging.RemoveAllExistingNamespaceElements)
            {
                var namespaceCleanser = container.Resolve <NamespaceCleanser>();
                namespaceCleanser.RemoveAllExistingNamespaceElements().Wait();
            }

            logger.Debug("Creating message pumps...");

            var messagePumps = new MessagePumpsManager(
                container.Resolve <ResponseMessagePumpFactory>().Create(),
                container.Resolve <RequestMessagePumpsFactory>().CreateAll(),
                container.Resolve <CommandMessagePumpsFactory>().CreateAll(),
                container.Resolve <MulticastRequestMessagePumpsFactory>().CreateAll(),
                container.Resolve <MulticastEventMessagePumpsFactory>().CreateAll(),
                container.Resolve <CompetingEventMessagePumpsFactory>().CreateAll(),
                container.Resolve <INimbusTaskFactory>());

            logger.Debug("Message pumps are all created.");

            var bus = new Bus(container.Resolve <ILogger>(),
                              container.Resolve <ICommandSender>(),
                              container.Resolve <IRequestSender>(),
                              container.Resolve <IMulticastRequestSender>(),
                              container.Resolve <IEventSender>(),
                              messagePumps,
                              container.Resolve <DeadLetterQueues>(),
                              container.Resolve <INimbusTaskFactory>(),
                              container.Resolve <IHeartbeat>());

            bus.Starting += delegate
            {
                container.Resolve <AzureQueueManager>().WarmUp();
                container.Resolve <PropertyInjector>().Bus = bus;
            };
            bus.Disposing += delegate { container.Dispose(); };

            logger.Info("Bus built. Job done!");

            return(bus);
        }